אתם מתרגלים שאלה מתוך מה"ט מבני נתונים ותכנות מונחה עצמים — הנדסאי תוכנהמבחן 2023 · אביב מועד ב · שאלה 8כל שאלות המבחן ←
תכנות מונחה עצמים›פולימורפיזם ומחלקות מופשטות

csharp

public class A { public A() { Console.WriteLine("A"); }

public virtual void One()
{
    Console.WriteLine("One of A");
}

public virtual void Two()
{
    Console.WriteLine("Two of A");
    this.One();
}

public  virtual void Four()
{
    Console.WriteLine ("Four of A");
    this.Two();
}

} //end of class A

public class B : A { public B() { Console.WriteLine("B"); }

public override void One()
{
    Console.WriteLine("One of B");
}

public override void Two()
{
    Console.WriteLine("Two of B");
}

public void Three()
{
    Console.WriteLine("Three of B");
    base.Two();
}

} //end of class B

public class C : B { public override void Four() { Console.WriteLine ("Four of C"); } } //end of class C

public class Test { public static void Main(string [] args) { // כאן יופיעו הפקודות שבסעיפים להלן } }

סעיף א

A a1 = new A(); ((B) a1).Two();

סעיף ב

B b1 = new B(); ((A) b1).Three();

סעיף ג

A a2 = new A(); a2.One(); ((A) a2).Two();

סעיף ד

A a3 = new B(); a3.Two(); ((B) a3).Two(); ((B) a3).Three();

סעיף ה

B b2 = new B(); b2.Two(); ((A) b2).Two();

סעיף ו

B b3 = new C(); b3.Four(); ((B)new C()).Four();

שאלות ותגובות על השאלה

🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות

שאלו כאן — ותקבלו מענה מוסמך.

🎓 מרצה לתכנות עונה כאן — תקבלו מענה מקצועי