טוען...
טוען...
לפניכם המחלקות A, B, C:
java1public class A {
2 public int num;
3
4 public A() {
5 this.num = 1;
6 }
7 public A(int num) {
8 this.num = num;
9 }
10 public int func (int val) {
11 return val * 2;
12 }
13 public int func (B other) {
14 return this.num - other.num;
15 }
16}
17
18public class B extends A {
19 public B() {
20 super(2);
21 }
22 public B(int val) {
23 super(val);
24 this.num = this.num + func (val);
25 }
26 public int func (A other) {
27 return this.num + (other.num * 10);
28 }
29 public int func (B other) {
30 return this.num + other.num;
31 }
32}
33
34public class C extends B {
35 public C(int val) {
36 this.num = this.num - val;
37 }
38 public int func (B other) {
39 return this.num * other.num;
40 }
41 public int func (C c) {
42 return this.num * 4;
43 }
44}
לפניכם קטע קוד שרץ ללא שגיאות:
java1A a = new A();
2A ab = new B();
3A ac = new C(0);
4B b = new B(1);
5B bc = new C(1);
6C c = new C(1);
הציגו את העצמים שנוצרו (סוג העצם, סוג ההפניה, וערך התכונה num).
לפניכם המשך קטע הקוד (ממוספר) שרץ ללא שגיאות.
ציינו את מספר שורת ההדפסה, וכתבו מה הקוד מדפיס.
java11. System.out.println (a.func (b));
22. System.out.println (a.func (c));
33. System.out.println (ab.func ((B)ab));
44. System.out.println (((B)ab).func (ab));
55. System.out.println (ab.func (10));
66. System.out.println (a.func (a.func (2)));
77. System.out.println (ac.func (c));
88. System.out.println (c.func (ac));
99. System.out.println (c.func (a));
1010. System.out.println (((C)bc).func ((C)bc));
לפניכם המחלקות A, B, C:
java1public class A {
2 public int num;
3
4 public A() {
5 this.num = 1;
6 }
7 public A(int num) {
8 this.num = num;
9 }
10 public int func (int val) {
11 return val * 2;
12 }
13 public int func (B other) {
14 return this.num - other.num;
15 }
16}
17
18public class B extends A {
19 public B() {
20 super(2);
21 }
22 public B(int val) {
23 super(val);
24 this.num = this.num + func (val);
25 }
26 public int func (A other) {
27 return this.num + (other.num * 10);
28 }
29 public int func (B other) {
30 return this.num + other.num;
31 }
32}
33
34public class C extends B {
35 public C(int val) {
36 this.num = this.num - val;
37 }
38 public int func (B other) {
39 return this.num * other.num;
40 }
41 public int func (C c) {
42 return this.num * 4;
43 }
44}
לפניכם קטע קוד שרץ ללא שגיאות:
java1A a = new A();
2A ab = new B();
3A ac = new C(0);
4B b = new B(1);
5B bc = new C(1);
6C c = new C(1);
הציגו את העצמים שנוצרו (סוג העצם, סוג ההפניה, וערך התכונה num).
לפניכם המשך קטע הקוד (ממוספר) שרץ ללא שגיאות.
ציינו את מספר שורת ההדפסה, וכתבו מה הקוד מדפיס.
java11. System.out.println (a.func (b));
22. System.out.println (a.func (c));
33. System.out.println (ab.func ((B)ab));
44. System.out.println (((B)ab).func (ab));
55. System.out.println (ab.func (10));
66. System.out.println (a.func (a.func (2)));
77. System.out.println (ac.func (c));
88. System.out.println (c.func (ac));
99. System.out.println (c.func (a));
1010. System.out.println (((C)bc).func ((C)bc));