| Author |
Inner Class
|
Richard Wilson
Ranch Hand
Joined: Jan 12, 2002
Posts: 57
|
|
What is the output when folllowing code is run? 1. class OuterOne{ 2. class InnerOne extends OuterOne{} 3. static void thisMethod(){ 4. Object o=(Object)new OuterOne(); 5. OuterOne foo=(OuterOne)o; 6. } 7. public static void main(String args[]){ 8. thisMethod(); 9. } 10. } 1. Will compile fine,but at runtime a ClassCastException is thrown 2. Will compile and run fine 3. Compiler error at line 4 4. Compiler error at line 5 Ans: 2 Why code here compiles fine? The Inner Class here is a member but why it can declare static method?
|
Richard Wilson
|
 |
Jose Botella
Ranch Hand
Joined: Jul 03, 2001
Posts: 2120
|
|
Ooops... the method is not within the inner class
|
SCJP2. Please Indent your code using UBB Code
|
 |
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
|
|
The static method is not in the inner class. [ February 17, 2002: Message edited by: Marilyn deQueiroz ]
|
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
|
 |
Richard Wilson
Ranch Hand
Joined: Jan 12, 2002
Posts: 57
|
|
Oh,so sorry for that mistake.I know now. [ February 17, 2002: Message edited by: Richard Wilson ]
|
 |
 |
|
|
subject: Inner Class
|
|
|