Help coderanch get a
new server
by contributing to the fundraiser
  • 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

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 ]
 
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic