Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"static class Inner construction"question required

 
PETER CARTER
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • 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 !!
 
Kay Liew
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Tom Tolman
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 !!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic