aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner Class" Watch "Inner Class" New topic
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: 9046
    
  10

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner Class