1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 class A {} 18 class B1 extends A {} 19 class B2 extends A {} 20 class C1 extends B1 {} 21 class C2 extends B1 {} 22 class D1 extends C1 {} 23 class D2 extends C2 {} 24 class E1 extends D1 {} 25 class E2 extends D2 {} 26 class F1 extends E1 {} 27 class F2 extends E2 {} 28 class G1 extends F1 {} 29 class G2 extends F2 {} 30 31 public class Main { 32 public static void main(String[] args) { 33 String yes = "Yes"; 34 String no = "No"; 35 36 A a = new A(); 37 A b1 = new B1(); 38 A b2 = new B2(); 39 A c1 = new C1(); 40 A c2 = new C2(); 41 A f1 = new F1(); 42 A f2 = new F2(); 43 A g1 = new G1(); 44 A g2 = new G2(); 45 46 expectFalse(b1 instanceof G1); 47 expectTrue(g1 instanceof B1); 48 expectFalse(b1 instanceof F1); 49 expectTrue(f1 instanceof B1); 50 51 expectFalse(b2 instanceof G1); 52 expectFalse(g1 instanceof B2); 53 expectFalse(b2 instanceof F1); 54 expectFalse(f1 instanceof B2); 55 56 expectFalse(g2 instanceof G1); 57 expectFalse(g1 instanceof G2); 58 expectFalse(f2 instanceof F1); 59 expectFalse(f1 instanceof F2); 60 61 expectTrue(g1 instanceof F1); 62 expectFalse(g1 instanceof F2); 63 expectFalse(g2 instanceof F1); 64 expectTrue(g2 instanceof F2); 65 66 System.out.println("passed"); 67 } 68 69 private static void expectTrue(boolean value) { 70 if (!value) { 71 throw new Error("Expected True"); 72 } 73 } 74 75 private static void expectFalse(boolean value) { 76 if (value) { 77 throw new Error("Expected False"); 78 } 79 } 80 } 81