Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner class & this statement in constructor

 
s deshpande
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I was wondering why does java allow publc constructors for private inner classes ? Is there any specific reason for this ? Since the inner class is private, we can not access it from outside class then why this public constructor ? I guess i'm missing something... pls help me out...
Also, why should "this" be first statement inside a constructor of a class ? For "super" i understand that before creating object of this class , we want the superclass object to be constructed fully .. but what is about "this" statement ?
TIA...
-Swapnil.
 
Alain Boucher
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 1:

How can you get a instance of a private class if their is no public constructor.

public class1{
private class2{
private class2(){}
}

public static void main(String args){
//How can I create a class2 here... the private constructor can only be instanciate inside the class2 method
}
}


Question 2:
super() call parent constructor
this() call default constructor of the current class
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic