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)

Java Other Question

Which three statements are true?

A. A method with the same signature as a private final method in class X can be implemented in a subclass of X.
B. A protected method in class X can be overridden by a subclass of A only if the subclass is in the same package as X.
C. A private static method can be called only within other static methods in class X.
D. A public static method in class X can be called by a subclass of X without explicitly referencing the class X.
E. A protected method in class X can be overridden by any subclass of X.
F. A final method in class X can be abstract if and only if X is abstract.
G. A non-static public final method in class X can be overridden in any subclass of X.
What will be the output of the following program?

class A
{
public void test()
{
System.out.println("Class A");
}
}
class Trial extends A
{
public void test()
{
System.out.println("Class Trial");
}
public static void main(String args[])
{
Trial object = (Trial)new A();
object.test();
}
}

A. Runtime Error
B. Compile Time Error
C. Class A
D. Class Trial