File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to instantiate a Class with the same name as an Inner Class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to instantiate a Class with the same name as an Inner Class?" Watch "How to instantiate a Class with the same name as an Inner Class?" New topic
Author

How to instantiate a Class with the same name as an Inner Class?

Sasha Ruehmkorf
Ranch Hand

Joined: Mar 29, 2007
Posts: 115
Hi.
A very small problem, but I cannot find a solution:
Suman Sharma
Ranch Hand

Joined: May 16, 2005
Posts: 72
Sasha,
I tried your example. This is how it works:

File: In.java

package abc;

public class In {

In() {
System.out.println("instantiating outer In class");
}

public static void main(String[] args ){

Out o = new Out();

o.method();

}

}

File: Out.java

package abc;

class Out {

void method(){
abc.In i = new abc.In();//instantiating outer In class

In in = new In(); // instantiating inner In class
}

class In
{
In() {
System.out.println("instantiating inner In class");
}
}
}

Output is:

instantiating outer In class
instantiating inner In class
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Here's my take on this.

separate In class:


Fubar1 class w/ internal In class:

[ May 09, 2007: Message edited by: pete stein ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to instantiate a Class with the same name as an Inner Class?