Skip to main content

Questions on Inheritance in Java

Here are some objective question on Inheritance and interfaces  in Java.
  • Which of the following statements are true about an abstract class?
    1. An abstract class can be instantiated 
    2. An abstract class can be subclassed
    3. An abstract class can not have a concrete method
    4. All of the above
  • Which of the following is the correct declaration of an interface?
    1. interface Test { public void print(){}}     
    2. interface Test { public void print(); }
    3. interface Test {   int a; void print(){}}
    4. All of the above
  • Which of the following statements are true?
    1. A final class can not be extended
    2. An abstract class can not be instantiated
    3. An interface can not be instantiated
    4. All of the above
 
  • What is the correct way of defining a class ABC which uses an interface DEF?
    1. class ABC extends DEF
    2. class DEF extends ABC
    3.  class ABC implements DEF
    4. None of the above
 
  • Method overriding is used to implement ------
    1. Inheritance
    2. Polymorphism
    3. Abstraction
    4. None of the above
 
  • A protected method in super class can have an overriding method in sub-class which is ------
    1. public
    2. private
    3. static
    4. None of the above
 
  • When we write a static method in subclass with the same signature as a static method in super class, it is called ------
    1. Method hiding
    2. Overriding
    3. Overloading
    4. None of the above
 
  • When we override a method in subclass, we can optionally using the annotation -----
    1. @override
    2. @Override
    3. @overrides
    4. None of the above
  • Except for Object class, every class has one and only one --------   
    1.  method    
    2. field   
    3. super class  
    4.  sub class
  By the way, if you would like to take an online quiz in Java, you can visit this site

Comments