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

Every method should have a commented header. It doesn\'t have to be long, but yo

ID: 3853727 • Letter: E

Question

Every method should have a commented header. It doesn't have to be long, but you should be able to use the method without having to read all the code in it.

Suppose that the following two classes have been declared public class Car { public void m1) System.out.println("car 1"); public void m2() I 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() I super.ml); public String toString) return super·toString() + super. toString(); Write a class MonsterTruck whose methods have the behavior below. Don't just print/return the output; whenever possible, use inheritance to reuse behavior from the superclass Method Output/Return monster 1 truck 1 car 1 toString "monster vroomvroom"

Explanation / Answer

Here is code:

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();
}
}

// inherted behavior from super class Car
public class MonsterTruck extends Car{
public void m1() {
System.out.println("monster 1");
}
public void m2() {
Truck t = new Truck();
// call Truck m1 method
t.m1();
// call supter class m1 method
super.m1();
}
public String toString() {
// return monster vroomvroom
return "monster "+ super.toString() + super.toString();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote