Java Programming and Technical Programming Output

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

Read Solution (Total 1)

Java Other Question

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
Which of the following statements are correct with respect to inheritance relationship in java?

A. object of subclass referenced by super class type can invoke super class methods
B. object of subclass referenced by super class type can access newly defined sub class variables
C. object of subclass referenced by super class type can access super class variables
D. object of subclass referenced by super class type can invoke overridden sub class methods
E. object of subclass referenced by super class type can invoke newly defined sub class methods