wood burning stoves 2.0
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inner class & this statement in constructor" Watch "inner class & this statement in constructor" New topic

inner class & this statement in constructor

s deshpande

Joined: Oct 18, 2004
Posts: 1
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 ?
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,
I agree. Here's the link: http://aspose.com/file-tools
subject: inner class & this statement in constructor
It's not a secret anymore!