Question ID: UK8296889
Given code of Test.java file:
package com.examtest.ocp;
class GrandParent {}
class Parent extends GrandParent {}
class Child extends Parent {}
class GrandChild extends Child {}
public class Test {
public static void main(String... args) {
GrandParent obj = new Child();
if(!(obj instanceof GrandChild gc)) {
System.out.print("Not a GrandChild");
/*INSERT-1*/
}
/*INSERT-2*/
System.out.println(gc); //Line n2
}
}
And the statements:
1. Above code causes compilation error
2. Above code compiles successfully and prints: Not a GrandChild
3. To resolve compilation error, replace /*INSERT-1*/ with return;
4. To resolve compilation error, replace /*INSERT-2*/ with else
How many of the above statements is/are correct?