And assuming that the following variables have been declared
And assuming that the following variables have been declared:
What is the output from the following statements?
| System.out.println(mycar); ______________ | |
| mycar.m1(); ______________ | |
| mycar.m2(); ______________ | |
| System.out.println(mytruck); ______________ | |
| mytruck.m1(); ______________ | |
| mytruck.m2(); ______________ | 
Solution
public class cars {
    public void m1(){
    System.out.println(\"in car1\");  
    }
 public void m2(){
    System.out.println(\"car 2\");
 }
 public String toString(){
    return \"vroom\";
 }
 }
 class Truck extends cars {
 public void m1() {
 System.out.println(\"truck 1\");
 }
 }
public class cheggmain {
   /**
    * @param args
    */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        cars mycar = new cars();
        Truck mytruck = new Truck();
        System.out.println(mycar);
    mycar.m1();
    mycar.m2();
        System.out.println(mytruck);
        mytruck.m1();
        mytruck.m2();
   
    }
}
output:
vroom
 in car1
 car 2
 vroom
 truck 1
 car 2

