JavaBeginner#oop

What is a constructor and how does constructor overloading work?

A constructor initializes a new object and has the same name as the class with no return type. Constructor overloading provides multiple constructors with different parameter lists so objects can be created in different ways.

Example
class Point {
  int x, y;
  Point() { this(0, 0); }
  Point(int x, int y) { this.x = x; this.y = y; }
}

Related Questions

1
JavaIntermediate#oop

What is the difference between instance initializer blocks and constructors?

Open
2
JavaBeginner#object#fundamentals

What is the difference between == and equals() when comparing objects that don't override equals()?

Open
3
JavaIntermediate#object#hashmap

What is the purpose of the hashCode() method and its contract with equals()?

Open