Java Inheritance
Interview Questions With Answers
Inheritance
Q:
1) What is the difference between superclass & subclass?
Ans : A super class is a class that is inherited whereas subclass is a
class that does the inheriting.
Q:
2) Which keyword is used to inherit a class?
Ans : extends
Q:
3) Subclasses methods can access superclass members/ attributes at all
times?
True/False
Ans : False
Q:
4) When can subclasses not access superclass members?
Ans : When superclass is declared as private.
Q:
5) Which class does begin Java class hierarchy?
Ans : Object class
Q:
6) Object class is a superclass of all other classes?
True/False
Ans : True
Q:
7) Java supports multiple inheritance?
True/False
Ans : False
Q:
8) What is inheritance?
Ans : Deriving an object from an existing class. In the other words,
Inheritance is the process of inheriting all the features from a class
Q:
9) What are the advantages of inheritance?
Ans : Reusability of code and accessibility of variables and methods of
the superclass by subclasses.
Q:
10) Which method is used to call the constructors of the superclass from
the subclass?
Ans : super(argument)
Q:
11) Which is used to execute any method of the superclass from the
subclass?
Ans : super.method-name(arguments)
Q:
12) Which methods are used to destroy the objects created by the
constructor methods?
Ans : finalize()
Q:
13) What are abstract classes?
Ans : Abstract classes are those for which instances can’t be created.
Q:
14) What must a class do to implement an interface?
Ans: It must provide all of the methods in the interface and identify the
interface in its implements clause.
Q:
15) Which methods in the Object class are declared as final?
Ans : getClass(), notify(), notifyAll(), and wait()
Q:
16) Final methods can be overridden.
True/False
Ans : False
Q:
17) Declaration of methods as final results in faster execution of the
program?
True/False
Ans: True
Q:
18) Final variables should be declared in the beginning?
True/False
Ans : True
Q:
19) Can we declare variable inside a method as final variables? Why?
Ans : Cannot because, local variable cannot be declared as final
variables.
Q:
20) Can an abstract class may be final?
Ans : An abstract class may not be declared as final.
Q:
21) Does a class inherit the constructors of it's super class?
Ans: A class does not inherit constructors from any of it's super classes.
Q:
22) What restrictions are placed on method overloading?
Ans: Two methods may not have the same name and argument list but
different return types.
Q:
23) What restrictions are placed on method overriding?
Ans : Overridden methods must have the same name , argument list , and
return type. The overriding method may not limit the access of the method
it overridees.The overriding method may not throw any exceptions that may
not be thrown by the overridden method.
Q:
24) What modifiers may be used with an inner class that is a member of an
outer class?
Ans : a (non-local) inner class may be declared as public, protected,
private, static, final or abstract.
Q:
25) How this() is used with constructors?
Ans: this() is used to invoke a constructor of the same class
Q:
26) How super() used with constructors?
Ans : super() is used to invoke a super class constructor
Q:
27) Which of the following statements correctly describes an interface?
a)It's a concrete class
b)It's a superclass
c)It's a type of abstract class
Ans: c
Q:
28) An interface contains __ methods
a)Non-abstract
b)Implemented
c)unimplemented
Ans:c
Java Inheritance Interview Questions With
Answers
Tolal:0 Click:
Show All Comments