¥Given
a class definition, Java provides a mechanism called new for creating new instances of the class.
¥To
exploit the new, the class must provide a special method called a constructor that specifies how the fields of the created object are initialized.
¥A
constructor method has the same name as the class and does not contain the return type in the heading.
¥Example:
¥ Entry(String n, String a, String p) {
¥ this.name = n;
¥ this.address = a;
¥ this.phone = p;
¥ }
¥If a
class does not include a constructor, Java provides a default constructor (of no arguments) that does nothing.
¥
¥