• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inner class & this statement in constructor

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Get out of my mind! Look! A tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic