This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic Applet Doubt

 
Satish Kota
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is that an applet constructor should be declared always public?

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The constructor is called by the JVM when is the applet is, well, constructed. It couldn't do that if the constructor wasn't public.
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
The constructor is called by the JVM when is the applet is, well, constructed. It couldn't do that if the constructor wasn't public.


Ulf Dittmer, if I am not wrong, this is true ONLY for JavaBeans and Applet. You can have a plain java class without constructor and JVM can create object of it.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because if the class does not have any constructor, the compiler will insert a public no-argument constructor for you. It doesn't do that if there is constructor, so if the one that's there isn't public, the class can't be instantiated by a non-subclass in a different package.
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic