# 메소드 오버라이딩(overriding) 모든 클래스 public double area에서 public이 없으면 출력이 안되는 이유가 생략되면 범위가 좁아져서 일까요? #### CODE <a class='btn btn-default' href='/codes/79509'>Link</a> ``` import java.lang.Math; public class Overriding { public static void main(String[] args) { Square s = new Square(); s.name = "정사각형"; s.length = 5; Triangle t = new Triangle(); t.name = "삼각형"; t.width = 4; t.height = 3; Circle c = new Circle(); c.name = "원"; c.radius = 4; Shape [] shapes = { s, t, c }; for(int i = 0; i< shapes.length; i++){ Shape tmp = shapes[i]; System.out.printf("%s의 넓이 -> %.2f\n", tmp.name, tmp.area()); } } } class Shape { String name; public double area (){ return 0; } } class Square extends Shape { int length; public double area(){ return length * length; } } class Triangle extends Shape { int width; int height; public double area(){ return width * height / 2; } } class Circle extends Shape { int radius; public double area(){ return Math.PI * radius * radius; } } ``` #### INPUT ``` ``` #### OUPUT ``` 정사각형의 넓이 -> 25.00 삼각형의 넓이 -> 6.00 원의 넓이 -> 50.27 ```
## public 이 없을 때의 실행 코드와 결과를 함께 보여주세요
제가 잘못 지웠나봅니다. public의 유무 상관없이 잘 출력되네요.