Examveda
Examveda

What will be the output of the following Java program?
class A 
{
    int i;
    public void display() 
    {
        System.out.println(i);
    }    
}    
class B extends A 
{
    int j;
    public void display() 
    {
        System.out.println(j);
    } 
}    
class Dynamic_dispatch 
{
    public static void main(String args[])
    {
        B obj2 = new B();
        obj2.i = 1;
        obj2.j = 2;
        A r;
        r = obj2;
        r.display();     
    }
}

A. 1

B. 2

C. 3

D. 4

Answer: Option B


This Question Belongs to Java Program >> Overriding And Overloading

Join The Discussion

Related Questions on Overriding and Overloading