נתונות המחלקות האלה: [A, B, D, Driver]. בכל אחד מהסעיפים הבאים (*****) תוחלף לקטע קוד רלוונטי.
נתונות המחלקות האלה: [A, B, D, Driver]. בכל אחד מהסעיפים הבאים (*****) תוחלף לקטע קוד רלוונטי.
public abstract class A {
public int x;
public A() {
this.x = 1;
}
public abstract int F(int v);
public virtual void F(A a) {
x = a.x;
}
public override
string ToString(){
return "x =" + this.x;
}
} //end of class A
public class B : A {
public B():base() {
}
public B(int val):base(){
this.x = F(val);
}
public override int F(int val){
return this.x + val;
}
public virtual void F(B b){
this.x = this.x * b.x;
}
public override string ToString(){
return "B: " + base.ToString();
}
} //end of class B
public class D : B {
public D(int val):base(){
this.x = val - this.x;
}
public override void F(A a){
this.x = this.x + a.x + 1;
}
public override void F(B b){
this.x = this.x * b.x;
}
public void F(D d) {
this.x = d.x - 1;
}
public override string ToString(){return "D: " + base.ToString();}
} //end of class D
public class Driver {
public static void Main (string [] args){
A a;
B b;
int m;
// ************
}
}
סעיף א
מהו הפלט של קטע הקוד שלפניכם:
m = 11;
a = new B(m);
Console.WriteLine(a);
a = new D(m);
Console.WriteLine(a);
סעיף ב
b = new B(3);
m = b.F(4);
Console.WriteLine(m);
m = b.F(m);
Console.WriteLine(m);
סעיף ג
a = new B(5);
m = a.F(a.F(2));
Console.WriteLine(m);
סעיף ד
a = new D(10);
b = new B(20);
a.F(b);
Console.WriteLine(a);
סעיף ה
אחרי ביצוע קטע הקוד הבא, הערך של התכונה x של העצם d יהיה 5. מהו הערך המשתנה של m?
D d = new D(m);
b = new B();
((A)d).F(b);
שאלות ותגובות על השאלה
🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות
שאלו כאן — ותקבלו מענה מוסמך.