Wednesday, May 7, 2008

Java Interview Questions 27

131. Question: Can a private method of a superclass be declared within a
subclass?
Answer: Sure. A private field or method or inner class belongs to its declared
class and hides from its subclasses. There is no way for private stuff to have a
runtime overloading or overriding (polymorphism) features.

132. Question: Why Java does not support multiple inheritence ?
Answer: Java DOES support multiple inheritance via interface implementation.

133. Question:What is the difference between final, finally and finalize?
Answer: o final - declare constant
o finally - handles exception
o finalize - helps in garbage collection

134. Question: Where and how can you use a private constructor.
Answer: Private constructor can be used if you do not want any other class to
instanstiate the object , the instantiation is done from a static public method,
this method is used when dealing with the factory method pattern when the designer
wants only one controller (fatory method ) to create the object.

135. Question: In System.out.println(),what is System,out and println,pls
explain?
Answer: System is a predefined final class,out is a PrintStream object and println
is a built-in overloaded method in the out object.

No comments:

Useful Information