Constructor Overloading in Java


Constructor overloading allows a class to have more than one constructor with different parameters.

Source Code

class Rectangle {
    int width, height;
    Rectangle() {
        this.width = 10;
        this.height = 10;
    }
    Rectangle(int w, int h) {
        this.width = w;
        this.height = h;
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments