Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

An applet constructor(Urgent)

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why is it not necessary to define constructors in Applet?
Thanks,
Angela
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't necessary to define constructors anywhere.
If you haven't defined any constructors, the compiler creates one for you that takes no arguments.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you're more curious about why you don't have to explicitly instantiate an applet when you might otherwise if it were an application (as perhaps one of the first commands in the main method).
The applet viewer or web browser does this for you by calling the no arg constructor (which the compiler may have created for you if you haven't defined any constructors).
Anything making sense?
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Dirk Schreckmann:
Perhaps you're more curious about why you don't have to explicitly instantiate an applet when you might otherwise if it were an application (as perhaps one of the first commands in the main method).
Anything making sense?


You mean that Parent Applet class has default constructor which will automatically called by web browser. Am I right???
Thanks,
Angela
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not exactly (or not directly at least). I mean that in the applet class you create, if you don't specify any constructors, the compiler creates a default no-argument constructor and this is invoked by the web browser. Because your applet extends the class Applet, the first thing that this default no-argument constructor does is invoke the parent class's (Applet's) default no-arguement constructor.
 
expectation is the root of all heartache - shakespeare. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic