Consider the following classes: Suppose the following variables are defined: Ind
ID: 3566066 • Letter: C
Question
Consider the following classes:
Suppose the following variables are defined:
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.
var1.method1(); var2.method1(); var3.method1(); var4.method1(); var5.method1(); var6.method1(); var1.method2(); var2.method2(); var3.method2(); var4.method2(); var5.method2(); var6.method2(); var3.method3(); var5.method3(); ((Larry) var1).method1(); ((Mary) var2).method2(); ((Jerry) var5).method1(); ((Mary) var5).method3(); ((Jerry) var4).method3(); ((Mary) var6).method3();Explanation / Answer
var1.method1();
harry 1
var2.method1();
larry 1 / harry 1
var3.method1();
larry 1 / harry 1
var4.method1();
larry 1 / harry 1
var5.method1();
larry 1 / harry 1
var6.method1();
The method method1() is undefined for the type Object
var1.method2();
harry 1 /harry 2
var2.method2();
larry 1 /harry 1 /harry 2
var3.method2();
mary 2 / jerry 2
var4.method2();
mary 2
var5.method2();
mary 2 /jerry 2
var6.method2();
The method method2() is undefined for the type Object
var3.method3();
The method method3() is undefined for the type Larry
var5.method3();
larry 1 /harry 1/mary 3
((Larry) var1).method1();
java.lang.ClassCastException: Harry cannot be cast to Larry
((Mary) var2).method2();
java.lang.ClassCastException: Larry cannot be cast to Mary
((Jerry) var5).method1();
larry 1 / harry 1
((Mary) var5).method3();
larry 1 /harry 1 /mary 3
((Jerry) var4).method3();
java.lang.ClassCastException: Mary cannot be cast to Jerry
((Mary) var6).method3();
java.lang.ClassCastException: Larry cannot be cast to Mary
var1.method1();
harry 1
var2.method1();
larry 1 / harry 1
var3.method1();
larry 1 / harry 1
var4.method1();
larry 1 / harry 1
var5.method1();
larry 1 / harry 1
var6.method1();
The method method1() is undefined for the type Object
var1.method2();
harry 1 /harry 2
var2.method2();
larry 1 /harry 1 /harry 2
var3.method2();
mary 2 / jerry 2
var4.method2();
mary 2
var5.method2();
mary 2 /jerry 2
var6.method2();
The method method2() is undefined for the type Object
var3.method3();
The method method3() is undefined for the type Larry
var5.method3();
larry 1 /harry 1/mary 3
((Larry) var1).method1();
java.lang.ClassCastException: Harry cannot be cast to Larry
((Mary) var2).method2();
java.lang.ClassCastException: Larry cannot be cast to Mary
((Jerry) var5).method1();
larry 1 / harry 1
((Mary) var5).method3();
larry 1 /harry 1 /mary 3
((Jerry) var4).method3();
java.lang.ClassCastException: Mary cannot be cast to Jerry
((Mary) var6).method3();
java.lang.ClassCastException: Larry cannot be cast to Mary
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.