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

Consider the following classes. You are only being shown the methods necessary f

ID: 3857287 • Letter: C

Question

Consider the following classes. You are only being shown the methods necessary for the problem -- you may assume each class has the appropriate constructors, etc. Consider the following classes: public class Blue extends Green { public void one() { System.out.println("Blue 1): super one(): } } public class Red extends Yellow { public void one() { super.one(): System.out.println("Red 1"): } public void two() { System.out.println("Red 2"): super.two(): } } public class Yellow extends Blue { public void two() { System.out.println ("Yellow 2"): } public void three() { two(): System.out.println("Yellow 3"): } } public class Green { public void one() { System.out.println("Green 1"): } public void threee() { System.out.println("Green 3"): } } //Suppose the following variables are defined: Green var l = new Blue(): Green var2 = new Red(): Blue var3 = new Yellow(): Object var4 = new Green(): Indicate on each line below the output produced by each statement shown. If the statement produces more than one line of output indicate the line breaks with slashes as in a/b/c to indicate three lines of output with a followed by b followed by c. If the statement causes an error, write the word error to indicate this. Indicate the output produced by each statement shown. If the statement produces more than one line of output indicate the line breaks with slashes as in a/b/c to indicate three lines of output with a followed by b followed by c. If the statement causes an error, write the word error to indicate this. a) var1.one(): b) var1.two(): c) var1.three(): d) var2.one(): e) var2.three(): f) var3.one(): g) var3.two(): h) var3.three(): i) var4.one():

Explanation / Answer

The answer is as follows:

a) var1.one();    Blue 1/Green 1 // In the function "one" of Blue class, there is a print for "Blue 1" and after that super.one is called (super is the base class
                                  // i.e Green class. So its "one" is called.

b) var1.two();    error   //two() is not a function in Blue or Green

c) var1.three()   Green 3

d) var2.one()     error // calling super.one() but yellow does not have this function

e) var2.three()   Yellow 2/ Yellow 3

f) var3.one()     Blue 1/Green 1

g) var3.two()     Yellow 2

h) var3.three()   Yellow 2/Yellow 3

i) var4.one()     Green 1

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