Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inner Class Names  RSS feed

 
Craig Oliver
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible for a regular inner class to have same name as outer class?

Does same rule apply to static inner classes?
 
Bhushan Damle
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
compile following code and see the error
public class InnerClass
{
public void show()
{
System.out.println("Hye-Bye");
}
public static void main(String args[])
{

new InnerClass().show();
class InnerClass
{
public void show()
{
System.out.println("Hello");
}
}

}
}

now compile this code and execute & see the output
public class InnerClass
{
public static void main(String args[])
{

class Inner
{
public void show()
{
System.out.println("Hello");
}
}
new Inner().show();
}

}
Hope, you have got the answer
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!