Thursday, May 29, 2008

Java Interview Questions 26

126. Question: Explain the Polymorphism principle.
Answer: The meaning of Polymorphism is something like one name many forms.
Polymorphism enables one entity to be used as as general category for different
types of actions. The specific action is determined by the exact nature of the
situation. The concept of polymorphism can be explained as "one interface, multiple
methods".

127. Question: Explain the different forms of Polymorphism.
Answer: From a practical programming viewpoint, polymorphism exists in three
distinct forms in Java:
• Method overloading
• Method overriding through inheritance
• Method overriding through the Java interface

128. Question: What are Access Specifiers available in Java?
Answer: Access specifiers are keywords that determines the type of access to the
member of a class. These are:
• Public
• Protected
• Private
• Defaults

129. Question: Describe the wrapper classes in Java.
Answer: Wrapper class is wrapper around a primitive data type. An instance of a
wrapper class contains, or wraps, a primitive value of the corresponding type.
Following table lists the primitive types and the corresponding wrapper classes:
Primitive Wrapper
boolean java.lang.Boolean
byte java.lang.Byte
char java.lang.Character
double java.lang.Double
float java.lang.Float
int java.lang.Integer
long java.lang.Long
short java.lang.Short
void java.lang.Void

130. Question: Read the following program:
public class test {
public static void main(String [] args) {
int x = 3;
int y = 1;
if (x = y)
System.out.println("Not equal");
else
System.out.println("Equal");
}
}
What is the result?
A. The output is “Equal”
B. The output in “Not Equal”
C. An error at " if (x = y)" causes compilation to fall.
D. The program executes but no output is show on console.
Answer: C

No comments:

Useful Information