Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following two classes: public class Car { public void m1() { System

ID: 3853723 • Letter: C

Question

Consider the following two classes: public class Car { public void m1() { System.out.println("car 1"): } public void m2() { System.out.println("car 2"): } public String toString() { return "vroom": } } public class Truck extends Car { public void m1() { System.out.println("truck 1"): } public void m2() { super.m1(): } public String toString() { return super.toString() + super.toString(): } } And assuming that the following variable has been declared: Truck mytruck = new Truck(): What is the output from the following statements? System.out.println(mytruck): _____ mytruck.m1(): _____ mytruck.m2(): _____

Explanation / Answer

Truck myTruck = new Truck();

here we are creating an Object to the "Truck" class.

when the statement executes System.out.println("mytruck");

This statement will displays the contents of an Truck class Object.

Output: v roomv room

___________________________

mytruck.m1();

when this statement executes, the Truck class m1() method will be executed which displays

Output: truck 1

___________________________

mytruck.m2();

when this statement executes, the Truck class m2() method will be executed.The code inside it is super.m1();

so the super class( Car ) m1() method will be called which displays

Output: car 1


_____________Could you rate me well.Plz .Thank You