Question
Which of the following method calls are valid ways to fill in the blank line of code? class Car{ public void m1(){ System.out.println(Car 1); }
Which of the following method calls are valid ways to fill in the blank line of code?
class Car{ public void m1(){ System.out.println("Car 1"); } public void m2(){ System.out.println("Car 2"); } public String toString(){ return "vroom"; } } class Truck extends Car{ public void m1() { System.out.println("Truck 1"); } public String toString() { return super.toString() + super.toString(); } public void m3() { System.out.println("Only in truck"); } }
public class Driver{ public static void main(String [] args){ Car mycar; mycar = new Car(); System.out.println(mycar);
__________________________________
} }
1)mycar.m2(); | ||
2)mycar.m3(); | ||
3)mycar.m1(); |
QUESTION 2
Which of the following method calls are valid ways to fill in the blank line of code?
class Car{ public void m1(){ System.out.println("Car 1"); } public void m2(){ System.out.println("Car 2"); } public String toString(){ return "vroom"; } } class Truck extends Car{ public void m1() { System.out.println("Truck 1"); } public String toString() { return super.toString() + super.toString(); } public void m3() { System.out.println("Only in truck"); } }
public class Driver{ public static void main(String [] args){ Truck mytruck; mytruck = new Truck();
System.out.println(mytruck);
__________________________________
} }
1)mytruck.m1(); | ||
2)mytruck.m3(); | ||
3)mytruck.m2(); |
QUESTION 3
Which of the following method calls are valid ways to fill in the blank line of code?
class Car{ public void m1(){ System.out.println("Car 1"); } public void m2(){ System.out.println("Car 2"); } public String toString(){ return "vroom"; } } class Truck extends Car{ public void m1() { System.out.println("Truck 1"); } public String toString() { return super.toString() + super.toString(); } public void m3() { System.out.println("Only in truck"); } }
public class Driver{ public static void main(String [] args){ Car mycar; mycar = new Truck();
System.out.println(mycar);
__________________________________
} }
1)mycar.m2(); | ||
2)mycar.m3(); | ||
3)mycar.m1(); |
QUESTION 4
What is the output of the following program?
class Car{ public void m1(){ System.out.println("Car 1"); } public void m2(){ System.out.println("Car 2"); } public String toString(){ return "vroom"; } } class Truck extends Car{ public void m1() { System.out.println("Truck 1"); } public String toString() { return super.toString() + super.toString(); } public void m3() { System.out.println("Only in truck"); } } public class Driver3{ public static void main(String [] args){ Car mycar; mycar = new Truck(); System.out.println(mycar); mycar.m1(); mycar.m2(); } }
1)vroom Truck 1 Car 2 | ||
2)The code is not valid. | ||
3)vroom Car 1 Car 2 | ||
4)vroomvroom Truck 1 Car 2 |
QUESTION 5
What is the output of the following program?
class Car{ public void m1(){ System.out.println("Car 1"); } public void m2(){ System.out.println("Car 2"); } public String toString(){ return "vroom"; } } class Truck extends Car{ public void m1() { System.out.println("Truck 1"); } public String toString() { return super.toString() + super.toString(); } public void m3() { System.out.println("Only in truck"); } } public class Driver3{ public static void main(String [] args){ Truck mytruck; mytruck = new Truck(); System.out.println(mytruck); mytruck.m1(); mytruck.m2(); mytruck.m3(); } }
1)The code is not valid. | ||
2)vroom Truck 1 Car 2 3Only in truck | ||
3)vroomvroom Truck 1 Car 2 Only in truck | ||
4)vroomvroom Truck 1 Only in truck |
QUESTION 6
Given the following class declarations, and the variable declared in the main method, which of the following statements are valid as a continuation to the main method?
class Bay extends Lake { public void method1() { System.out.println("Bay 1"); } public void method2() { System.out.println("Bay 2"); } } class Pond { public void method1() { System.out.println("Pond 1"); } public void method2() { System.out.println("Pond 2"); } } class Ocean extends Bay { public void method2() { System.out.println("Ocean 2"); } } class Lake extends Pond { public void method3() { System.out.println("Lake 3"); } } public class Water { public static void main(String [] args) { Pond var1 = new Bay(); } }
1)var1.method2(); | ||
2)var1.method1(); | ||
3)((Lake) var1).method1(); | ||
4)((Bay) var1).method1(); | ||
5)((Pond) var1).method1(); | ||
6)((Ocean) var1).method1(); |
QUESTION 7
What is the output of the following program?
class Bay extends Lake { public void method1() { System.out.println("Bay 1"); } public void method2() { System.out.println("Bay 2"); } } class Pond { public void method1() { System.out.println("Pond 1"); } public void method2() { System.out.println("Pond 2"); } } class Ocean extends Bay { public void method2() { System.out.println("Ocean 2"); } } class Lake extends Pond { public void method3() { System.out.println("Lake 3"); } } public class Water { public static void main(String [] args) { Pond var1 = new Bay();
((Lake) var1).method1(); ((Bay) var1).method1(); ((Pond) var1).method1(); } }
1)Bay 1 Pond 1 Pond 1 | ||
2)Bay 1 Bay 1 Bay 1 | ||
3)Pond 1 Bay 1 Pond 1 | ||
4)Lake 1 Bay 1 Pond 1 |
QUESTION 8
Given the following class declarations, and the variable declared in the main method, which of the following statements are valid as a continuation to the main method? class Bay extends Lake { public void method1() { System.out.println("Bay 1"); } public void method2() { System.out.println("Bay 2"); } } class Pond { public void method1() { System.out.println("Pond 1"); } public void method2() { System.out.println("Pond 2"); } } class Ocean extends Bay { public void method2() { System.out.println("Ocean 2"); } } class Lake extends Pond { public void method3() { System.out.println("Lake 3"); } } public class Water { public static void main(String [] args) { Pond var2 = new Bay(); } }
1)((Ocean) var2).method3(); | ||
2)var2.method1(); | ||
3)((Lake) var2).method2(); | ||
4)var2.method3(); | ||
| ||
5) var2.method2(); | ||
6)((Pond) var2).method3(); | ||
7)((Pond) var2).method2(); |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started