Java Inheritance Mcqs

Our collections of Multiple choice questions and answers focuses on study of Java Inheritance. These questions are chosen from a collection of most authoritative and best reference books on Java. Our aim is to prepare an individual for competitive exams like NTS, GAT, ECAT, University and College entrance exams and various tests and job interviews. One should practice our Mcqs to assimilate Java Inheritance topic comprehensively.

19.
What would be the result if a class extends two interfaces and both have a method with same name and signature?

Runtime error

Compile time error

Code runs successfully

First called method is executed successfully

21.
What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?

Method overloading

Method overriding

Method hiding

None of the mentioned

26.
What is the output of this program?

 class Alligator 
 {
  public static void main(String[] args) 
   {
   int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};
   int [][]y = x;
   System.out.println(y[2][1]);
   }
 }

2

3

7

Compilation Error

27.
What is the output of this program?

   final class A 
    {
         int i;
    }    
    class B extends A 
    {
        int j;
        System.out.println(j + " " + i);  
    }    
    class inheritance 
    {
        public static void main(String args[])
        {
            B obj = new B();
            obj.display();     
        }
   }

2 2

3 3

Runtime Error

Compilation Error

28.
What is the output of this program?

  class Abc
  {
      public static void main(String[]args)
      {
          String[] elements = { "for", "tea", "too" };
          String first = (elements.length > 0) ? elements[0]: null;
      }
  }

Compilation error

An exception is thrown at run time

The variable first is set to null

The variable first is set to elements[0].

29.
What is the output of this 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();     
        }
   }

1

2

3

4

30.
What is the output of this program?

    class Output 
    {
        public static void main(String args[])
        {
             Object obj = new Object();
	     System.out.print(obj.getclass());
        }
    }

Object

Class Object

Class java.lang.Object

Compilation Error

31.
What is the output of this program?

   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());
        }
   }

True

False

String associated with obj1

Compilation Error

0Shares
0
Scroll to Top