class InstanceofDemo
{
public static void main(String[] args)
{
Parent object1 = new Parent();
Parent object2 = new Child();
System.out.println("object1 instanceof Parent: "
+ (obj1 instanceof Parent));
System.out.println("object1 instanceof Child: "
+ (obj1 instanceof Child));
System.out.println("object1 instanceof MyInterface: "
+ (obj1 instanceof MyInterface));
System.out.println("object2 instanceof Parent: "
+ (obj2 instanceof Parent));
System.out.println("object2 instanceof Child: "
+ (obj2 instanceof Child));
System.out.println("object2 instanceof MyInterface: "
+ (obj2 instanceof MyInterface));
}
}
The above code defines a parent class (named Parent ), a simple interface (named MyInterface ), and a child class (named Child ) that inherits from the parent and implements the interface.
Following program execution, what will be the output of the six println statements?
Correct Answer:
Verified
obj1 instanceof Paren...
View Answer
Unlock this answer now
Get Access to more Verified Answers free of charge
Q63: public class ASuperClass
{
public
Q64: Create a class named Student that contains
Q65: What is the process of inlining and
Q66: You have a Student class with a
Q67: What is information hiding and how is
Q69: class Vehicle {}
public class Car extends
Q70: How is the keyword protected used?
Q71: Using a class named Student , write
Q72: What are virtual method calls?
Q73:
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents