Consider the following Java code snippet:
class Animal {
}
class Dog extends Animal {
}
class Cat extends Animal {
}
public class Test {
public static void main(String[] args) {
Animal a = new Dog();
/* Missing Statements ? */
}
}
Which two of the following statements, inserted independently, could legally be inserted into the missing section of this code?
1. boolean isDog = (a instanceof Dog);
2. boolean isCat = (a instanceof Cat);
3. boolean isAnimal = (a instanceof Animal);
4. boolean isDog = (Dog instanceof a);
Choose the correct answer from the options given below:
1
1 and 2
2
1 and 3
3
2 and 3
4
1 and 4
5
Question Not Attempted