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
this
as a name for another constructor in the same class. Any call tothis
must 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 ...
Get Java: An Introduction to Problem Solving and Programming, 8th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.