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

java

public class A { protected int x; public A() { x = 0; } public void method(int num) { x += num; } public String toString() { return "" + x; } }// end of class A

public class B extends A { private int y; public B() { super(); y = 1; } public void method(int num) { x -= num; y += num; } public String toString() { return "" + x + "." + y; } }// end of class B

public class C extends A { private int y; public C() { super(); y = 10; } public void method(int num) { x += num; y += num; } public 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 ++)
    {
        System.out.println ("array[" + i + "] = " + array[i]);
        array[i].method(i+2);
        System.out.println ("array[" + i + "] = " + array[i]);
    }
}

}

סעיף א

עקבו אחרי ביצוע הפעולה הראשית של המחלקה Test וכתבו מה יהיה הפלט של הפעולה. חובה להציג באיור את כל העצמים שנוצרו ואת ערכי התכונות שלהם.

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

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

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

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