Question: Java: Inheritance and Polymorphism public class Blue extends Green { public void one() { System.out.println(Blue 1); super.one(); } // end one } // end Blue

Java: Inheritance and Polymorphism

public class Blue extends Green { public void one() { System.out.println("Blue 1"); super.one(); } // end one } // end Blue

public class Red extends Yellow { public void one() { super.one(); System.out.println("Red 1"); } // end one public void two() { System.out.println("Red 2"); super.two(); } // end two } // end Red

public class Yellow extends Blue { public void two() { System.out.println("Yellow 2"); } // end two public void three() { two(); System.out.println("Yellow 3"); } // end three } // end Yellow

public class Green { public void one() { System.out.println("Green 1"); } // end one public void three() { System.out.println("Green 3"); } // end three } // end Green

The following variables are defined:

Green var1 = new Blue(); Green var2 = new Red(); Blue var3 = new Yellow(); Object var4 = new Green();

Indicate the output produced by the statements below. If the statement causes an error, indicate as such.

var1.one(); var1.two(); var1.three(); var2.one(); var2.two(); var2.three(); var3.two(); var4.one(); ((Blue) var1).one(); ((Yellow) var1).two(); ((Red) var2).three(); ((Yellow) var2).two(); ((Green) var4).three(); ((Yellow) var4).two();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!