Menu
Question Index
...

What will be the output of the program?

class OutPut
{
    public static void main (String [] args)
    {
        Tree tree = new Oak();
        
        if( tree instanceof Tree )
            System.out.println ("Output is Tree.");
        
        else if( tree instanceof Oak )
            System.out.println ( "Output is Oak.");
        
        else
            System.out.println ("Output is Oops.");
    }
}
class Tree
{

}
class Pine extends Tree
{

}
class Oak extends Pine
{

}


Output is Tree.
Output is Pine.
Output is Oak.
Compilation Error

Doubts

Problems

Topic: Assigning Super Class Reference To A Sub Class Reference In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App