• 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 Classes

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import Outer.Inner.InnerMost;
import Outer.*;

class Outer {
int i;
class Inner {
Inner() {i++;}

class InnerMost extends Inner {
InnerMost() {i++; System.out.println(i);}
}
}
interface InnerInterface {
void doSomething();
}
}

public class Test implements InnerInterface{

public void doSomething(){
System.out.println("done");
}

public static void main(String[] args){
Inner im = new Outer().new Inner().new InnerMost();
}
}

How is the output 3?
Thanks
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am assuming that you figured out 2 of the places where i gets incremented. The third is the super class of the innermost class. Remember the innermost class extends the inner class.

Henry
 
Michael Carlson
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey thanks, it just occurred to me. I always post questions as last resort, and then I get it.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic