Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
public class OuterClass{
class InnerClass{
}
public void innerClassDemo(){
//Explicit instance of InnerClass
}
}
In above example, how can you explicitly create an instance of InnerClass?
A. InnerClass i=InnerClass();
B. InnerClass i=OuterClass.InnerClass();
C. InnerClass i=new OuterClass ().new InnerClass();
D. OuterClass.InnerClass i=new OuterClass.InnerClass();
Ans. is C,D; I picked C and that too I think it should be
OuterClass.InnerClass i = new OuterClass().new InnerClass();
29. An inner class created inside a method can access
A. Any local variables of a method that contain an inner class.
B. Any instance variables of the enclosing class
C. Any final variables of the enclosing class or a method that contain an inner class.
D. None of the above
Ans is C. Me thinks its B,C
32. Please select invalid statement(s) for a thread
A. You can restart a dead thread
B. You can't call the methods of a dead thread
C. Both of the above
D. None of the above
The ans. is D. Isn't A invalid? I didn't think you could restart a dead thread.
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
SCJP2. Please Indent your code using UBB Code
DRAFT
There is also a special null type, the type of the expression null, which has no
name. Because the null type has no name, it is impossible to declare a variable of
the null type or to cast to the null type. The null reference is the only possible
value of an expression of null type. The null reference can always be cast to any
reference type. In practice, the programmer can ignore the null type and just pretend
that null is merely a special literal that can be of any reference type.
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |