Skip to content

Instantly share code, notes, and snippets.

@stden
Created March 21, 2017 17:21
Show Gist options
  • Select an option

  • Save stden/d35780a879ab45ed4c71e54e7df8e8fd to your computer and use it in GitHub Desktop.

Select an option

Save stden/d35780a879ab45ed4c71e54e7df8e8fd to your computer and use it in GitHub Desktop.
Пример наследования
package shapes;
public class Main {
public static void main(String[] args) {
Shape[] shapes = {
new Circle("Окружность", "Красный", 1.0, 2.0, 1.5),
new Point("Точка", "Чёрная", 2.3, 3.1),
new Square("Квадрат", "Пурпурный",
1.0, 2.0, 4.0, 5.0),
new Triangle("Треугольник", "Синий",
1, 2, 3, 4, 5, 6)
};
// Shape абстрактный и не может быть создан
// Shape shape = new Shape();
for (Shape shape : shapes) {
shape.move(1.0, 2.0);
}
for (Shape shape : shapes) {
shape.show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment