Menu
Topics Index
...
`

Classes851


If you need explanation Read this topic

If you need Answer Take test on this topic

Classes851
What will be the output of the program?
class OutPut
{
    public static void main (String [] args)
    {
        Tree tree = new Pine();
        
        if( tree instanceof Pine )
            System.out.println ("Output is Pine.");
        
        else 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 Tree
{


}

A. Output is Tree.
B. Output is Pine.
C. Output is Oak.
D. Compilation Error
Topic: Assigning Super Class Reference To A Sub Class Reference In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans B, Pine is extending Tree class Porperties so tree is a instance of the Pine class

Posted by Damu Surya    2014-08-27 04:02:07


ans c...Pine is extending Tree class Porperties so tree is a instance of the Pineclass

Posted by Shamee Shamee    2014-08-27 04:07:44


Ans is B.
as we are creating Pine object and Pine is extending  Tree class. so tree is instance of Pine class.

Posted by Gopinath Manchikanti    2014-08-27 06:19:43


ans b

Posted by Pranavi Prakash    2014-08-27 08:06:17


Congratulations Damodar You. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-28 05:22:32


© meritcampus 2019

All Rights Reserved.

Open In App