Created
July 6, 2026 14:48
-
-
Save thinkphp/540a5f66aad4d5cbc1cedc1824f1e06a to your computer and use it in GitHub Desktop.
polimorfism.java
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
| class Shape { | |
| void draw() { | |
| System.out.println("Desenez o forma geometrica"); | |
| } | |
| } | |
| //subclasa 1 | |
| class Circle extends Shape { | |
| @Override | |
| void draw() { | |
| System.out.println("Desenez un cerc"); | |
| } | |
| } | |
| //subclasa 2 | |
| class Square extends Shape { | |
| @Override | |
| void draw() { | |
| System.out.println("Desenez un Patrat"); | |
| } | |
| } | |
| //subclasa 3 | |
| class Triangle extends Shape { | |
| @Override | |
| void draw() { | |
| System.out.println("Desenez un Triunghi"); | |
| } | |
| } | |
| public class Polimorfism { | |
| public static void main(String[] args) { | |
| Shape shape1 = new Circle(); | |
| Shape shape2 = new Square(); | |
| Shape shape3 = new Triangle(); | |
| shape1.draw(); | |
| shape2.draw(); | |
| shape3.draw(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment