Chapter Summary
A constructor is a method that creates and initializes an object of the class when you invoke it using the operator
new. A constructor must have the same name as the class.A constructor without parameters is called a default constructor. A class that does not define a constructor will be given a default constructor automatically. A class that defines one or more constructors, none of which is a default constructor, will have no default constructor.
When defining a constructor for a class, you can use
thisas a name for another constructor in the same class. Any call tothismust be the first action taken by the constructor.The declaration of a static variable contains the keyword
static. A static variable is shared by all the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access