טוען...
טוען...
לפניכם המחלקות E, F, G, H:
java1public class E {
2 protected int x;
3 public E(){
4 this.x = 5;
5 System.out.println("E x = " + this.x);
6 }
7 public E(int x) {
8 this.x = x;
9 }
10 public int calc() {
11 return this.x;
12 }
13}
14
15public class F extends E {
16 private static int count = 0;
17 public F() {
18 super(8);
19 count++;
20 }
21 public F(int x) {
22 super(x);
23 count++;
24 System.out.println("F count = " + count);
25 }
26 public int calc() {
27 return this.x + 10;
28 }
29}
30
31public class G extends F {
32 public G() {
33 super(3);
34 this.x =this.x* 2;
35 System.out.println("G x = " + this.x);
36 }
37 public int calc() {
38 return super.calc() + 1;
39 }
40 public int squre() {
41 return this.x*this.x;
42 }
43}
44
45public class H extends E {
46 public H() {
47 super();
48 this.x = this.x + 5;
49 System.out.println("H x = " + this.x);
50 }
51 public int calc() {
52 return this.x/2;
53 }
54}
נתונה המחלקה Tester:
java1public class Tester
2{
3 public static void main(String[] args)
4 {
5 E e1 = new E();
6 E e2 = new F();
7 F f1 = new G();
8 E e3 = new H();
9 E a = new G();
10 E b = new H();
11 F c = new G();
12 // ***
13 }
14}
הציגו את העצמים שנוצרו בפעולה main (סוג העצם, סוג ההפנייה וערכי התכונות), וכתבו את הפלט של הפעולה.
הציבו כל אחת מן הפקודות 1–10 שלהלן בפעולה main במקום המצוין לעיל ב־// ***.
כתבו במחברת את מספר הפקודה וציינו אם הקוד המתקבל תקין או לא תקין. אם הקוד תקין – כתבו את הפלט. אם הקוד אינו תקין, הסבירו מדוע.
שימו לב
אין קשר בין הפקודות הבאות. הפקודות אינן תלויות זו בזו.
java11. F f = new E();
22. G g = new F();
33. F f2 = (F)a;
44. G g2 = (G)c;
55. F f3 = (F)b;
66. System.out.println(((G)a).squre());
77. System.out.println(a.squre());
88. System.out.println(((H)b).calc());
99. System.out.println(((G)b).squre());
1010. System.out.println(f1.squre());
לפניכם המחלקות E, F, G, H:
java1public class E {
2 protected int x;
3 public E(){
4 this.x = 5;
5 System.out.println("E x = " + this.x);
6 }
7 public E(int x) {
8 this.x = x;
9 }
10 public int calc() {
11 return this.x;
12 }
13}
14
15public class F extends E {
16 private static int count = 0;
17 public F() {
18 super(8);
19 count++;
20 }
21 public F(int x) {
22 super(x);
23 count++;
24 System.out.println("F count = " + count);
25 }
26 public int calc() {
27 return this.x + 10;
28 }
29}
30
31public class G extends F {
32 public G() {
33 super(3);
34 this.x =this.x* 2;
35 System.out.println("G x = " + this.x);
36 }
37 public int calc() {
38 return super.calc() + 1;
39 }
40 public int squre() {
41 return this.x*this.x;
42 }
43}
44
45public class H extends E {
46 public H() {
47 super();
48 this.x = this.x + 5;
49 System.out.println("H x = " + this.x);
50 }
51 public int calc() {
52 return this.x/2;
53 }
54}
נתונה המחלקה Tester:
java1public class Tester
2{
3 public static void main(String[] args)
4 {
5 E e1 = new E();
6 E e2 = new F();
7 F f1 = new G();
8 E e3 = new H();
9 E a = new G();
10 E b = new H();
11 F c = new G();
12 // ***
13 }
14}
הציגו את העצמים שנוצרו בפעולה main (סוג העצם, סוג ההפנייה וערכי התכונות), וכתבו את הפלט של הפעולה.
הציבו כל אחת מן הפקודות 1–10 שלהלן בפעולה main במקום המצוין לעיל ב־// ***.
כתבו במחברת את מספר הפקודה וציינו אם הקוד המתקבל תקין או לא תקין. אם הקוד תקין – כתבו את הפלט. אם הקוד אינו תקין, הסבירו מדוע.
שימו לב
אין קשר בין הפקודות הבאות. הפקודות אינן תלויות זו בזו.
java11. F f = new E();
22. G g = new F();
33. F f2 = (F)a;
44. G g2 = (G)c;
55. F f3 = (F)b;
66. System.out.println(((G)a).squre());
77. System.out.println(a.squre());
88. System.out.println(((H)b).calc());
99. System.out.println(((G)b).squre());
1010. System.out.println(f1.squre());