Answer to Question #5586 in AJAX | JavaScript | HTML | PHP for denise

Question #5586
What is the answer? Polymorphism and dynamic binding (4 points total; 1 point each part) Consider the following three classes: public class Gee { public String first() { return "fee"; } public String second() { return "fi"; } } public class Tee extends Yee { public String first() { return "fo"; } } public class Yee extends Gee { public String second() { return "fum" + first(); } public String third() { return "from"; } } Assume that you have the following variable declarations, all of which are valid: Gee g = new Yee(); Yee y1 = new Yee(); Yee y2 = new Tee(); Tee t = new Tee(); Consider the following statements. If a given statement would compile, state the output that it would produce when it is executed. If a given statement would not compile, explain why. System.out.println(g.first() + " " + g.second() + " " + g.third()); System.out.println(y1.first() + " " + y1.second() + " " + y1.third()); System.out.println(y2.first() + " " + y2.second() + " " + y2.third()); System.out.println(t.first() + " " + t.second() + " " + t.third());
Expert's answer

1. System.out.println(g.first() + " " + g.second() + " " + g.third());
// this statement is not valid because the method third() is undefined for the type Gee

2. System.out.println(y1.first() + " " + y1.second() + " " + y1.third());
//result is “fo fumfo from”

3. System.out.println(y2.first() + " " + y2.second() + " " + y2.third());
//result is “fee fumfee from”

4. System.out.println(t.first() + " " + t.second() + " " + t.third());
//result is “fo fumfo from”

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS
paypal