go to previous page   go to home page   go to next page

Answer:

No.


Work Behind the Scenes

The default constructor does a great deal of work behind the scenes. It works with the Java virtual machine to find main memory for the object, sets up that memory as an object, puts in the variables and methods specified in the class definition, and returns an object reference to your program. All of this is quite complicated, and it is fortunate that you don't have to write code for it.

If you need to initialize some variables in a newly constructed object, then write a constructor as part of the class. All your constructor needs is statements that initialize the variables. The "behind the scenes" work is included automatically.

Syntax Rule: If you define one or more constructors for a class, then those are the only constructors that the class has. The default constructor is supplied automatically only if you define no constructors.

This rule makes sense. If you are defining constructors for a class, then it is likely that you want to have control over the process and don't want an extra default constructor.


QUESTION 14:

(Design Question: ) In our design so far, every HelloObject object prints the same string to the monitor. How could this class be improved?


go to previous page   go to home page   go to next page