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
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