Saturday, May 10, 2008

Java Interview Questions 43

211. What is meant by Inheritance and what are its advantages?
Ans. Inheritance is the process of inheriting all the features from a class. The
advantages of inheritance are reusability of code and accessibility of variables
and methods of the super class by subclasses.

212. What is the difference between this() and super()?
Ans. this() can be used to invoke a constructor of the same class whereas super()
can be used to invoke a super class constructor.

213. What is the difference between superclass and subclass?
Ans. A super class is a class that is inherited whereas sub class is class that
does the inheriting.

214. What modifiers may be used with top-level class?
Ans. public, abstract and final can be used for top-level class.

215. What are inner class and anonymous class?
Ans. Inner class : classes defined in other classes, including those defined in
methods are called inner classes. An inner class can have any accessibility
including private. Anonymous class : Anonymous class is a class defined inside a
method without a name and is instantiated and declared in the same place and cannot
have explicit constructors.

No comments:

Useful Information