• 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

"static class Inner construction"question required

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class Outer {
public void someOuterMethod() {

}
public static class Inner{
}
public static void main( String[] args ) {
Outer o = new Outer();
o.Inner();//I believe it is right .
}
}
Why it compiles fails ?

E:\l>javac Outer.java
Outer.java:9: cannot resolve symbol
symbol : method Inner ()
location: class Outer
o.Inner();
^
1 error
Thanks !!
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe it should be something like this.

Outer.Inner u = o.new Inner();

Instead of "o.Inner();" Inner is not a method, you can't instantiate it like method. It's inner class.

Similar question can be found in Kathy and Berts book Chapter 8 and very last question. I saw this couple weeks ago in that book and I do not have any reference with me now.

If you do not have KB book, this url should do. Scroll down until you find TestMe class.

http://www.javaranch.com/campfire/StoryInner.jsp

Anyway, bother to share where do you get those question from ?



k

[ September 17, 2004: Message edited by: Kay Liew ]
[ September 17, 2004: Message edited by: Kay Liew ]
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peter,

I enjoy reading your posts. I think I would enjoy them more if you got the indendting going on the code. Probably the [ code ] [/ code ] would do the trick (around your code).

Thanks for listening
 
PETER CARTER
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1:
public class Outer {
public void someOuterMethod() {

}
public static class Inner{
}
public static void main( String[] args ) {
Outer.Inner b=new Outer.Inner();
}
}
2:
public class Outer {
public void someOuterMethod() {

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

The two Inner class constructions are all right!
Thanks !!
reply
    Bookmark Topic Watch Topic
  • New Topic