File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes inner class & this statement in constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inner class & this statement in constructor" Watch "inner class & this statement in constructor" New topic
Author

inner class & this statement in constructor

s deshpande
Greenhorn

Joined: Oct 18, 2004
Posts: 1
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

Joined: Feb 25, 2003
Posts: 51
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


Alain Boucher<br />Spare-Brain Consultants Inc.<br />SCJ2P,SCWCD,
 
 
subject: inner class & this statement in constructor