Created
March 21, 2017 17:21
-
-
Save stden/d35780a879ab45ed4c71e54e7df8e8fd to your computer and use it in GitHub Desktop.
Пример наследования
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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