csharp
public class A { protected int x; public A() { x = 0; } public virtual void Method(int num) { x += num; } public override string ToString() { return "" + x; } }// end of class A
public class B : A { private int y; public B() { y = 1; } public override void Method(int num) { x -= num; y += num; } public override string ToString() { return "" + x + "." + y; } }// end of class B
public class C : A { private int y; public C() { y = 10; } public override void Method(int num) { x += num; y += num; } public override string ToString() { return "" + x + "/"+ y; } } // end of class C
public class Test { public static void Main (string [] args) { A [] array = new A[4]; array[0] = new C(); array[1] = new B(); array[2] = new A(); array[3] = new B();
for (int i = 0; i < array.Length; i ++)
{
Console.WriteLine ("array[" + i + "] = " + array[i]);
array[i].Method(i+2);
Console.WriteLine ("array[" + i + "] = " + array[i]);
}
}
}
עקבו אחרי ביצוע הפעולה הראשית של המחלקה Test וכתבו מה יהיה הפלט של הפעולה. חובה להציג באיור את כל העצמים שנוצרו ואת ערכי התכונות שלהם.
שאלות ותגובות על השאלה
🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות
שאלו כאן — ותקבלו מענה מוסמך.