This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inner Class  RSS feed

 
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: 9079
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 ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!