Abstract class A{void display(){}}class B extends A{void display(){}psvm(String args[]){how can i instantiate the overridden method in class A}}

Showing Answers 1 - 4 of 4 Answers

Alok

  • Oct 27th, 2005
 

 A a1 = new b();

a1.display();

  Was this answer useful?  Yes

Devidas

  • Nov 14th, 2005
 

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

  Was this answer useful?  Yes

abstract class A

{

    void
display()
    {
    }
}

class B extends A

{

    void
display()
    {

        super
.display();

        -----------------
    }

    public
static void main(String args[])

    {
       
B b1=new B();

       
b1.display();
    }
}

  Was this answer useful?  Yes

all three answers above are correct. in 3rd one we are assigning object of B to reference of B itself. But in first and second answers we are assigning object of B to Reference of A. In all three cases JVM will invoke B's display() only.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions