Suppose I have four classes A, B, C and Container
and I have the following objects and How to achieve the following output by only adding code to the container class?
the first call by "con" object should correspond to the the first parameter.
Your answer will be greatly appreciated !
A a = new A();
B b = new B();
C c = new C();
Container con = new Container(a,b,c);
con.calling();
con.calling();
con.calling();
the expected output is :
calling from A
calling from B
calling from C
public class A {
public void callA() {
System.out.println("calling from A");
}
}
public class B {
public void callB() {
System.out.println("calling from B");
}
}
public class C {
public void callC() {
System.out.println("calling from C");
}
}
public class Container {
public Container(A a, B b, C c) {
}
public void calling(){
}
}
Aucun commentaire:
Enregistrer un commentaire