A class can contain both of the following method definitions: public int howMany
ID: 3818746 • Letter: A
Question
A class can contain both of the following method definitions:
public int howMany (int numberOfCouples) {
return 2 * numberOfCouples;
}
public double howMany (int numberOfCouples) {
return 2.3 * numberOfCouples;
}
Select one:
True
False
Question 2
A class can contain both of the following method definitions:
public int convertedValue(int number) {
if(number > 0)
return number;
return 0;
}
public int convertedValue(int numberToConvert) {
if(number > 0)
return number;
return 0;
}
Select one:
True
False
Question 3
A class can contain both of the following method definitions:
public int howMany () {
return ( (int) howMany(1));
}
public double howMany (int num) {
return 2.3 * num;
}
Select one:
True
False
Question 4
What is printed when the code snippets below are run?
public class MyClass {
int num;
public MyClass() {
num = 5;
}
public void doSomething(int num) {
System.out.print(this.num);
System.out.print(num);
}
}
// CODE IN A DRIVER PROGRAM:
MyClass myClass = new MyClass();
myClass.doSomething(3);
Select one:
53
none of the above
35
an error will be thrown
Question 5
What happens when "this" is used in a constructor’s body to call another constructor of the same class but the call is not the first statement in the constructor?
For example:
public Student(String name, String id) {
this.id = id;
this(name);
}
Select one:
a runtime error occurs
a compilation error occurs
a logic error occurs
nothing happens- the program compiles and runs
Question 6
A static method can do which of the following? Select all that apply.
Select one or more:
invoke other static methods in the class
invoke non-static methods in the class
reference instance data variables in the class
reference static variables in the class
Question 7
A non-static (instance) method can do which of the following? Select all that apply.
Select one or more:
reference instance data variables in the class
invoke other non-static methods in the class
invoke static methods in the class
reference static variables in the class
Question 8
Based on the following code fragments, which of the following are legal statements? Select all that apply.
public class Bird {
public Bird() {
...
}
public int getFlightSpeed() { ...}
public static int getMaximumFlightSpeed() { ...}
}
Select one or more:
Bird b = new Bird();
Bird b = new Bird();
int n = b.getFlightSpeed();
int n = Bird.getMaximumFlightSpeed();
int n = Bird.getFlightSpeed();
Explanation / Answer
Question 1:
False,because the data type is different but it is not satisfying the method overloading.
Question 4:
53
Queestion 5:
a compilation error occurs
Because constructor call shoukd be the statement in a constructor
Question 6:
Question 7:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.