• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inner Class

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ooops... the method is not within the inner class
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh,so sorry for that mistake.I know now.
[ February 17, 2002: Message edited by: Richard Wilson ]
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic