CSE143 Inheritance Example Assuming that the following classes have been defined: public class MusicPlayer { public void method1() { System.out.println("MusicPlayer1"); } } public class TapeDeck extends MusicPlayer { public void method3() { System.out.println("TapeDeck3"); } } public class IPod extends MusicPlayer { public void method2() { System.out.println("IPod2"); method1(); } } public class IPhone extends IPod { public void method1() { System.out.println("IPhone1"); super.method1(); } public void method3() { System.out.println("IPhone3"); } } And assuming the following variables have been defined: MusicPlayer var1 = new TapeDeck(); MusicPlayer var2 = new IPod(); MusicPlayer var3 = new IPhone(); IPod var4 = new IPhone(); Object var5 = new IPod(); Object var6 = new MusicPlayer(); In the table below, indicate in the right-hand column the output produced by the statement in the left-hand column. 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, fill in the right-hand column with either the phrase "compiler error" or "runtime error" to indicate when the error would be detected. Statement Output ------------------------------------------------------------------ var1.method1(); ____________________________ var2.method1(); ____________________________ var3.method1(); ____________________________ var4.method1(); ____________________________ var5.method1(); ____________________________ var6.method1(); ____________________________ var4.method2(); ____________________________ var4.method3(); ____________________________ ((TapeDeck) var1).method2(); ____________________________ ((IPod) var1).method2(); ____________________________ ((TapeDeck) var1).method3(); ____________________________ ((IPhone) var2).method1(); ____________________________ ((IPhone) var3).method1(); ____________________________ ((IPhone) var4).method3(); ____________________________ ((MusicPlayer) var5).method1(); ____________________________ ((IPod) var3).method2(); ____________________________ ((IPhone) var5).method2(); ____________________________ ((IPod) var5).method2(); ____________________________ ((MusicPlayer) var6).method1(); ____________________________ ((MusicPlayer) var6).method2(); ____________________________ ((TapeDeck) var6).method3(); ____________________________ Solution to CSE143 Inheritance Example Statement Output -------------------------------------------------- var1.method1(); MusicPlayer1 var2.method1(); MusicPlayer1 var3.method1(); IPhone1/MusicPlayer1 var4.method1(); IPhone1/MusicPlayer1 var5.method1(); compiler error var6.method1(); compiler error var4.method2(); IPod2/IPhone1/MusicPlayer1 var4.method3(); compiler error ((TapeDeck) var1).method2(); compiler error ((IPod) var1).method2(); runtime error ((TapeDeck) var1).method3(); TapeDeck3 ((IPhone) var2).method1(); runtime error ((IPhone) var3).method1(); IPhone1/MusicPlayer1 ((IPhone) var4).method3(); IPhone3 ((MusicPlayer) var5).method1(); MusicPlayer1 ((IPod) var3).method2(); IPod2/IPhone1/MusicPlayer1 ((IPhone) var5).method2(); runtime error ((IPod) var5).method2(); IPod2/MusicPlayer1 ((MusicPlayer) var6).method1(); MusicPlayer1 ((MusicPlayer) var6).method2(); compiler error ((TapeDeck) var6).method3(); runtime error