AP Computer Science A › Method Declarations
1. class test
2. {
3. public:
4. test();
5. exams(int);
6. quiz(int);
7. private:
8. int grade;
9. }
Which line represents the constructor?
4
1
3
8
6
The constructor looks like a function declaration but always has the same name of the class.
True or False.
This code snippet defines a method that takes in two strings as input and will return a boolean as a result.
public void returnBoolean (String input1, String input2);
False
True
The prompt specifies that the return type of the method is a boolean. The return type of the method in the code snippet is void. Therefore, it will not return anything. The two input types however are correct.
1. class test
2. {
3. public:
4. test();
5. exams(int);
6. quiz(int);
7. private:
8. int grade;
9. }
Which line represents the constructor?
4
1
3
8
6
The constructor looks like a function declaration but always has the same name of the class.
1. class test
2. {
3. public:
4. test();
5. exams(int);
6. quiz(int);
7. private:
8. int grade;
9. }
Which line represents the constructor?
4
1
3
8
6
The constructor looks like a function declaration but always has the same name of the class.
True or False.
This code snippet defines a method that takes in two strings as input and will return a boolean as a result.
public void returnBoolean (String input1, String input2);
False
True
The prompt specifies that the return type of the method is a boolean. The return type of the method in the code snippet is void. Therefore, it will not return anything. The two input types however are correct.
True or False.
This code snippet defines a method that takes in two strings as input and will return a boolean as a result.
public void returnBoolean (String input1, String input2);
False
True
The prompt specifies that the return type of the method is a boolean. The return type of the method in the code snippet is void. Therefore, it will not return anything. The two input types however are correct.
Write the stub for a public method named writeToConsole that takes in a boolean b and a string s that returns an integer.
public int writeToConsole(boolean b, string s)
public void writeToConsole(boolean b, string s)
public writeToConsole(boolean b, string s)
public int writeToConsole()
Public methods are prefixed with the word public. The second word is the return type (i.e. int). The third is the name of the method and inside the parentheses goes the inputs to the method (i.e. boolean b and string s).
Fill in the blank.
A ______ function does not specify a return type, but may have any number of inputs.
void
empty
constructor
int
double
Remember, a void function does not need a return type. The void keyword tells the program not to expect a return statement. A void function does not necessarily mean that the inputs are void as well. A void function can still have any number of inputs of any type.
Fill in the blank.
A ______ function does not specify a return type, but may have any number of inputs.
void
empty
constructor
int
double
Remember, a void function does not need a return type. The void keyword tells the program not to expect a return statement. A void function does not necessarily mean that the inputs are void as well. A void function can still have any number of inputs of any type.
Write the stub for a public method named writeToConsole that takes in a boolean b and a string s that returns an integer.
public int writeToConsole(boolean b, string s)
public void writeToConsole(boolean b, string s)
public writeToConsole(boolean b, string s)
public int writeToConsole()
Public methods are prefixed with the word public. The second word is the return type (i.e. int). The third is the name of the method and inside the parentheses goes the inputs to the method (i.e. boolean b and string s).