Vidyalelo
Java Programming · all questions

Inheritence
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

86

Questions

4/5

Page

Pick an option on a question to see the right answer and solution.

Which of these is not a correct statement?

Select an option to see the answer and solution.

What will be the output of the following Java code?
class Output 
{
    public static void main(String args[])
    {
         Object obj = new Object();
   System.out.print(obj.getclass());
    }
}

Select an option to see the answer and solution.

Which of the following is used for implementing inheritance through an interface?

Select an option to see the answer and solution.

Which of these is correct way of inheriting class A by class B?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class A 
{
    public int i;
    public int j;
    A() 
    {
        i = 1;
        j = 2;
}
}    
class B extends A 
{
    int a;
    B() 
    {
        super();
    } 
}    
class super_use 
{
    public static void main(String args[])
    {
        B obj = new B();
        System.out.println(obj.i + " " + obj.j)     
    }
}

Select an option to see the answer and solution.

Which of these packages contains abstract keyword?

Select an option to see the answer and solution.

Which of these class relies upon its subclasses for complete implementation of its methods?

Select an option to see the answer and solution.

Which of these keywords can be used to prevent inheritance of a class?

Select an option to see the answer and solution.

Static members are not inherited to subclass.

Select an option to see the answer and solution.

Which of these keywords are used to define an abstract class?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of these is not abstract?

Select an option to see the answer and solution.

Does Java support multiple level inheritance?

Select an option to see the answer and solution.

What will be the output of the following Java code?
class A 
{
    public int i;
    private int j;
}    
class B extends A 
{
    void display() 
    {
        super.j = super.i + 1;
        System.out.println(super.i + " " + super.j);
    }
}    
class inheritance 
{
    public static void main(String args[])
    {
        B obj = new B();
        obj.i=1;
        obj.j=2;   
        obj.display();     
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java code?
class A 
{
    public int i;
    protected int j;
}    
class B extends A 
{
    int j;
    void display() 
    {
        super.j = 3;
        System.out.println(i + " " + j);
    }
}    
class Output 
{
    public static void main(String args[])
    {
        B obj = new B();
        obj.i=1;
        obj.j=2;   
        obj.display();     
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java code?
class A 
{
     int i;
int j;
     A() 
     {
         i = 1;
         j = 2;
     }
}
class Output 
{
     public static void main(String args[])
     {
          A obj1 = new A();
    System.out.print(obj1.toString());
     }
}

Select an option to see the answer and solution.

Which of this keyword must be used to inherit a class?

Select an option to see the answer and solution.

Which of these class is superclass of every class in Java?

Select an option to see the answer and solution.

Which of these keywords cannot be used for a class which has been declared final?

Select an option to see the answer and solution.