This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Eclipse Collections Categorically: Level up your programming game and have Donald Raab on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
A very small problem, but I cannot find a solution:
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's my take on this.

separate In class:


Fubar1 class w/ internal In class:

[ May 09, 2007: Message edited by: pete stein ]
 
Those are the largest trousers in the world! Especially when next to this ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic