Wednesday, May 7, 2008

Java Interview Questions 28

136. What is meant by "Abstract Interface"?
Answer: First, an interface is abstract. That means you cannot have any
implementation in an interface. All the methods declared in an interface are
abstract methods or signatures of the methods.

137. Question: Can you make an instance of an abstract class? For example -
java.util.Calender is an abstract class with a method getInstance() which returns
an instance of the Calender class.
Answer: No! You cannot make an instance of an abstract class. An abstract class has
to be sub-classed. If you have an abstract class and you want to use a method which
has been implemented, you may need to subclass that abstract class, instantiate
your subclass and then call that method.

138. What is the output of x < y? a:b = p*q when x=1,y=2,p=3,q=4?
Answer: When this kind of question has been asked, find the problems you think is necessary to ask before you give an answer. Ask if variables a and b have been
declared or initialized. If the answer is yes. You can say that the syntax is
wrong. If the statement is rewritten as: x
<y? a:(b=p*q); the return value would be
variable a because the x is 1 and less than y = 2; the x
< y statement return true
and variable a is returned.


139. Question: What is the difference between Swing and AWT components?

Answer: AWT components are heavy-weight, whereas Swing components are lightweight.
Heavy weight components depend on the local windowing toolkit. For example,
java.awt.Button is a heavy weight component, when it is running on the Java
platform for Unix platform, it maps to a real Motif button.

140. Why Java does not support pointers?
Answer: Because pointers are unsafe. Java uses reference types to hide pointers and
programmers feel easier to deal with reference types without pointers. This is why
Java and C# shine.

No comments:

Useful Information