1 Interface Myinterface 2 Int Number 3 4 Abstract Class Abs 5 Static Int Foo 12 1 (57.7 KiB) Viewed 37 times
1 Interface Myinterface 2 Int Number 3 4 Abstract Class Abs 5 Static Int Foo 12 2 (20.93 KiB) Viewed 37 times
/* 1 */ interface MyInterface { /* 2 */ int number(); /* 3 */ } /* 4 */ abstract class Abs { /* 5 */ static int foo = 12; /* 6 */ int number() { return 5; } 7 */ abstract int ace(); /* 8 */ } /* 9 */ final class Sub extends MainClass { /* 10 */ Sub(int bar) { foo = bar; } /* 11 */ int number() { return 10; } /* 12 */ int ace() { return 13; } /* 13 */ int dubble (int i) { return 2 * i; } /* 14 */ } /* 15 */ public class Mainclass extends Abs implements MyInterface /* 16 */ /* 17 */ /* 18 */ /* 19 */ /* 20 */ /* 21 */ /* 22 */ /* 23 */ /* 24 */ /* 25 */ } public int number() { return 11; } public static void main(String args[]) { MainClass sl = new MainClass(); MainClass s2 = new Sub (16); System.out.println( foo ); 1 int twice (int x) { return 2 * x; } int ace() { return 1; } String dubble (String s) { return s + S; } a. Identify the syntax error on line 11. Explain it briefly (1 pt) b. Fix the code and find the output of the program (Line 20) (1 pt) C. The method defined on line overrides the method defined on line (give only one case) (1 pt)
d. At line 20, what would be printed if foo was replaced by: Choose two lines only from the table below. (4 pts) s1.ace() s2.acel) s1.foo s1.twice(3) s2.twice(3) s1.dubble(6) s2.dubble(7) s1.number() s2.number() s1.dubble("8") s2.dubble("9") s2.foo
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!