csharp
public class A { protected int i; public A (int i) { this.i = i; } }
public class B : A { public B (int i) : base (i + 1) { } public bool Foo (Object myObject) { Console.WriteLine ("Foo1"); return ((myObject is B) && (this.i == ((B)myObject).i)); } public virtual bool Foo (B myB, int num) { Console.WriteLine ("Foo2"); return (this.i + myB.i) < num; } }
public class C : B { public C (int i) : base (i) { } public bool Foo (int num) { Console.WriteLine ("Foo3"); return (this.i != num); } }
public class D : B { public D (int i) : base (i * 2) { } public override bool Foo (B myB, int num) { Console.WriteLine ("Foo4"); return base.Foo (myB, 20 ); } }
// --- המחלקה Tester (סעיף ב) --- public class Tester { public static void Main (string[] args) { A a = new A (1); B b = new B (2); C c = new C (3); D d = new D (4); B bd = new D (5); A ac = new C (6); //*** } }
סרטטו את תרשים ההייררכייה של המחלקות A , B , C , D . יש לסמן ירושה באמצעות החץ ◁——— .
נתונה המחלקה Tester : (הקוד מופיע בתחילת השאלה.) סרטטו את העצמים שנוצרו בפעולה Main .
במקום המסומן ב־*** נוסף קטע הקוד התקין שלפניכם:
Console.WriteLine (c.Foo(5)); //(1) Console.WriteLine (d.Foo(a)); //(2) Console.WriteLine (bd.Foo(b)); //(3) Console.WriteLine (bd.Foo(b, 1)); //(4) Console.WriteLine (((C)ac).Foo(c)); //(5)
כתבו את הפלט של הפעולה (כתבו את מספר השורה המשויך לכל פלט).
שאלות ותגובות על השאלה
🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות
שאלו כאן — ותקבלו מענה מוסמך.