wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark ""static class Inner construction"question required" Watch ""static class Inner construction"question required" New topic
Author

"static class Inner construction"question required

PETER CARTER
Ranch Hand

Joined: Aug 28, 2004
Posts: 70
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

Joined: Dec 26, 2003
Posts: 112
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 ]

Unity can only be manifested by the Binary. Unity itself and the idea of Unity are already two.
Tom Tolman
Ranch Hand

Joined: Sep 02, 2004
Posts: 83
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

Joined: Aug 28, 2004
Posts: 70
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
 
subject: "static class Inner construction"question required
 
Similar Threads
Outside code as an Inner class
Unable to Understand - import and classpath scjp 6
Inner Classes
Inner class question
classpath problem