• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner Class

 
Richard Wilson
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooops... the method is not within the inner class
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The static method is not in the inner class.
[ February 17, 2002: Message edited by: Marilyn deQueiroz ]
 
Richard Wilson
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh,so sorry for that mistake.I know now.
[ February 17, 2002: Message edited by: Richard Wilson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic