Java
Programming and Technical
Programming
Output
What will be the output of the program?
class Tree { }
class Pine extends Tree { }
class Oak extends Tree { }
public class Forest1
{
public static void main (String [] args)
{
Tree tree = new Pine();
if( tree instanceof Pine )
System.out.println ("Pine");
else if( tree instanceof Tree )
System.out.println ("Tree");
else if( tree instanceof Oak )
System.out.println ( "Oak" );
else
System.out.println ("Oops ");
}
}
A. Oops
B. Tree
C. Pine
D. Forest
Read Solution (Total 1)
-
- C. Pine,The tree reference points to an object of the Pine class.
- 1 Month agoHelpfull: Yes(0) No(0)
Java Other Question