לפניכם המחלקות A, B ו-Tester:
1public class A {
2 public A() { System.out.println("ctor A"); }
3 public void foo(int x) {
4 System.out.println("A foo int " + x);
5 }
6 public void foo(double y) {
7 System.out.println("A foo double " + y);
8 }
9 public void bar(int x) {
10 System.out.println("A bar " + x);
11 foo(x);
12 }
13}
14
15public class B extends A {
16 public B() { System.out.println("ctor B"); }
17 public void foo(int x) {
18 System.out.println("B foo int " + x);
19 }
20 public void bar() {
21 System.out.println("B bar");
22 foo(2);
23 }
24 public void another(int x) {
25 System.out.println("B another " + x);
26 super.foo(x);
27 foo(2.0 * x);
28 }
29}
30
31public class Tester {
32 public static void main(String[] args)
33 {
34 }
35}לפניכם 15 קטעי קוד. בחרו עשרה מהם.
הציבו כל אחד מקטעי הקוד שבחרתם בפעולה main במחלקה Tester, כתבו את מספר הקטע וציינו אם הקוד תקין או אינו תקין. אם הקוד תקין — כתבו את הפלט, ואם הוא אינו תקין — הסבירו את השגיאה. קטעי הקוד אינם קשורים זה לזה.
A a = new A(); a.foo(2);A a = new A(); ((B)a).foo(3);A a = new A(); B b = a; b.foo(2);A x = new B(); x.foo(2);A x = new B(); x.bar();A a = new A(); a.bar(3);A a = new A(); a.bar();B b = new B(); b.bar();B b = new B(); b.bar(3);B b = new B(); b.foo(2); b.foo(2.0);A a = new A(); a.foo(2); a.foo(2.0);B b = new A(); b.another(2);A a = new A(); a.another(2);B x = new B(); x.another(2);A x = new B(); x.another(2);לפניכם המחלקות A, B ו-Tester:
1public class A {
2 public A() { System.out.println("ctor A"); }
3 public void foo(int x) {
4 System.out.println("A foo int " + x);
5 }
6 public void foo(double y) {
7 System.out.println("A foo double " + y);
8 }
9 public void bar(int x) {
10 System.out.println("A bar " + x);
11 foo(x);
12 }
13}
14
15public class B extends A {
16 public B() { System.out.println("ctor B"); }
17 public void foo(int x) {
18 System.out.println("B foo int " + x);
19 }
20 public void bar() {
21 System.out.println("B bar");
22 foo(2);
23 }
24 public void another(int x) {
25 System.out.println("B another " + x);
26 super.foo(x);
27 foo(2.0 * x);
28 }
29}
30
31public class Tester {
32 public static void main(String[] args)
33 {
34 }
35}לפניכם 15 קטעי קוד. בחרו עשרה מהם.
הציבו כל אחד מקטעי הקוד שבחרתם בפעולה main במחלקה Tester, כתבו את מספר הקטע וציינו אם הקוד תקין או אינו תקין. אם הקוד תקין — כתבו את הפלט, ואם הוא אינו תקין — הסבירו את השגיאה. קטעי הקוד אינם קשורים זה לזה.
A a = new A(); a.foo(2);A a = new A(); ((B)a).foo(3);A a = new A(); B b = a; b.foo(2);A x = new B(); x.foo(2);A x = new B(); x.bar();A a = new A(); a.bar(3);A a = new A(); a.bar();B b = new B(); b.bar();B b = new B(); b.bar(3);B b = new B(); b.foo(2); b.foo(2.0);A a = new A(); a.foo(2); a.foo(2.0);B b = new A(); b.another(2);A a = new A(); a.another(2);B x = new B(); x.another(2);A x = new B(); x.another(2);