• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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: 23959
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.
reply
    Bookmark Topic Watch Topic
  • New Topic