Answered Questions

  • Referencing of Instances

    class A { // some code here} class B { // some code here}class Ex {public static void main(string args[]) {A a=new B();B b=new A();a.add();b.add();}Will this program run? Explain the referencing the object instances. What is the result;

    foiaz

    • Dec 27th, 2007

    Yes, this program will execute. Reference variables a and b holds the object instance of Class B and Class A respectively. i.e it points to the memory locations of those objects.a.add() will call the add() method of Class B. and b.add() will call the add() method of Class A.