Ниже представлено правильное решение:
package com.javarush.task.jdk13.task05.task0513;
/*
Собираем прямоугольник
*/
public class Rectangle {
public int left;
public int top;
public int width;
public int height;
public void initialize(int left, int top, int width, int height) {
this.left = left;
this.top = top;
this.width = width;
this.height = height;
}
public void initialize(int left, int top) {
this.left = left;
this.top = top;
this.width = 0;
this.height = 0;
}
public void initialize(int left, int top, int width) {
this.left = left;
this.top = top;
this.width = width;
this.height = width;
}
public void initialize(Rectangle rectangle) {
this.left = rectangle.left;
this.top = rectangle.top;
this.width = rectangle.width;
this.height = rectangle.height;
}
public static void main(String[] args) {
}
}
Не очень понятно почему вместо первых 3 блоков инициализации нельзя просто написать 1 вот такой:
public void initialize(int left, int top, int width, int height) {
this.left = left;
this.top = top;
this.width = 0;
this.height = 0;
}
Спасибо заранее за ответ!