Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Private inner class with private constructor

tahirakramJan 20 2009 — edited Jan 20 2009
I read that if constructor is public then you need a static method to create the object of that class.
But in the following scenario why I am able to get the object of PrivateStuff whereas it has private constructor.
I am messing with this concept.
public class Test {
	 public static void main(String[] args) {		 
		 Test t = new Test();
		 PrivateStuff p = t.new PrivateStuff();
	    }
	 
	 private class PrivateStuff{
		 private PrivateStuff(){
			 System.out.println("You stuff is very private");
		 }
	 }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 17 2009
Added on Jan 20 2009
3 comments
1,674 views