89. 타입 검사 후 다운캐스팅과 형 변환 예외
다음 Java 프로그램의 실행 결과가 첫 줄 "27", 둘째 줄 "cast fail 7"이 되도록 빈칸 ①에 들어갈 연산자를 쓰시오.
1class Shape {2int size() {3return 1;4}5}67class Circle extends Shape {8int r;910Circle(int r) {11this.r = r;12}1314int size() {15return r * r * 3;16}17}1819class Rect extends Shape {20int w;21int h;2223Rect(int w, int h) {24this.w = w;25this.h = h;26}2728int size() {29return w * h;30}3132int round() {33return 2 * (w + h);34}35}3637public class Main {38public static void main(String[] args) {39Shape[] arr = {new Circle(2), new Rect(3, 4), new Shape()};40int total = 0;41for (Shape s : arr) {42if (s ( ① ) Rect) {43Rect r = (Rect) s;44total += r.round();45} else {46total += s.size();47}48}49System.out.println(total);50try {51Rect bad = (Rect) arr[0];52System.out.println(bad.w);53} catch (ClassCastException e) {54System.out.println("cast fail " + total % 10);55}56}57}