A good answer might be:Not directly. But some other class which does have a main() method can used this class. | |
ConstructorsAn object is a section of memory (with variables and methods), and a class is a description of a possible object. When an object is created (instatiated) the description is followed. One way in which objects are created is when the new operator is used with a constructor. Here is the example program again:
A constructor has the same name as the class. The line from the above program
creates a new object of type String.
The new operator
says to create a new object.
It is followed by the name of a constructor.
The constructor String() is part of the definition for
the class String.
Constructors often are used with values (called parameters) that are to be stored in the data part of the object that is created. In the above program, the characters "Random Jottings" (not including the quote marks) are stored in the data section of the new object. There are usually several different constructors in a class, each with different parameters. Sometimes one is more convenient to use than another, depending on how the new object's data is to be initialized. However, all the constructors of a class follow the same plan in creating an object. | |
QUESTION 14:(Thought question:) Could a constructor be used a second time to change the values of an object it created? Click Here after you have answered the question |