Constructing objects with (new)
| |||
To instantiate an object in Java, use the keyword new
followed by a call to the class's constructor. Here's how you'd create a
new Car variable called c :
The first word, Car , declares the type of the
variable c . Classes are types and variables of a class type
need to be declared just like variables that are ints or doubles.
The equals sign is the assignment operator and Finally notice the This is often condensed into one line like this:
| |||
|