001package types.instanceOf; 002class C {} 003class Main { 004 private Main() {} 005 public static void f1(Object x) { 006 if (x instanceof C) 007 System.out.println("C"); 008 else 009 System.out.println("not C"); 010 } 011 public static void f2(Object x) { 012 boolean printed = false; 013 try { 014 C y = (C) x; 015 } catch (ClassCastException e) { 016 System.out.println("C"); 017 printed = true; 018 } finally { 019 if (!printed) 020 System.out.println("not C"); 021 } 022 } 023 public static void main(String[] args) { 024 Main.f1(new C()); 025 Main.f1(new Object()); 026 Main.f2(new C()); 027 Main.f2(new Object()); 028 } 029}