טוען...
טוען...
נתונות המחלקות AA, BB:
java1public class AA {
2 private int x;
3 public AA() { this.x = 4; }
4 public AA(int x) { this.x = x; }
5 public int getX() { return this.x; }
6 public void foo() { this.x = 3; }
7 public void goo() { this.x = this.x + 3; }
8 public void bar() { goo(); }
9 public String toString() { return "x = " + this.x; }
10}
java1public class BB extends AA {
2 private int y;
3 public BB() {
4 super();
5 this.y = 2;
6 }
7 public BB (int a) {
8 super (a);
9 this.y = getX() * 2;
10 }
11 public BB (int a, int b) {
12 super (a);
13 this.y = b;
14 }
15 public int getY() { return this.y; }
16 public void foo() { this.y = 5; }
17 public void goo() { this.y = getX() – 1; }
18 public void bar (int a) {
19 this.y = a + getX() + this.y;
20 }
21 public String toString() {
22 return super.toString() + " y = " + this.y;
23 }
24}
לפניכם קטע קוד:
java1AA[] items = new AA[6];
2items[0] = new AA();
3items[1] = new BB();
4items[2] = new AA(2);
5items[3] = new BB(2);
6items[4] = new BB(1, 22);
7items[5] = items[4];
8for (int i = 0; i < items.length; i++)
9 System.out.println(items[i]);
ציירו את העצמים שנוצרו, וכתבו מה הקוד מדפיס.
לפניכם המשך קטע הקוד:
java1items[0].foo();
2items[1].goo();
3((AA) items[3]).goo();
4items[4].bar();
5BB temp = new BB(1);
6temp.bar();
7System.out.println("Temp: " + temp);
8temp.bar(9);
9items[2] = temp;
10for (int i = 0; i < items.length; i++)
11 System.out.println(items[i]);
כתבו מה הקוד מדפיס.
נתונות המחלקות AA, BB:
java1public class AA {
2 private int x;
3 public AA() { this.x = 4; }
4 public AA(int x) { this.x = x; }
5 public int getX() { return this.x; }
6 public void foo() { this.x = 3; }
7 public void goo() { this.x = this.x + 3; }
8 public void bar() { goo(); }
9 public String toString() { return "x = " + this.x; }
10}
java1public class BB extends AA {
2 private int y;
3 public BB() {
4 super();
5 this.y = 2;
6 }
7 public BB (int a) {
8 super (a);
9 this.y = getX() * 2;
10 }
11 public BB (int a, int b) {
12 super (a);
13 this.y = b;
14 }
15 public int getY() { return this.y; }
16 public void foo() { this.y = 5; }
17 public void goo() { this.y = getX() – 1; }
18 public void bar (int a) {
19 this.y = a + getX() + this.y;
20 }
21 public String toString() {
22 return super.toString() + " y = " + this.y;
23 }
24}
לפניכם קטע קוד:
java1AA[] items = new AA[6];
2items[0] = new AA();
3items[1] = new BB();
4items[2] = new AA(2);
5items[3] = new BB(2);
6items[4] = new BB(1, 22);
7items[5] = items[4];
8for (int i = 0; i < items.length; i++)
9 System.out.println(items[i]);
ציירו את העצמים שנוצרו, וכתבו מה הקוד מדפיס.
לפניכם המשך קטע הקוד:
java1items[0].foo();
2items[1].goo();
3((AA) items[3]).goo();
4items[4].bar();
5BB temp = new BB(1);
6temp.bar();
7System.out.println("Temp: " + temp);
8temp.bar(9);
9items[2] = temp;
10for (int i = 0; i < items.length; i++)
11 System.out.println(items[i]);
כתבו מה הקוד מדפיס.