Java Programming and Technical Programming Technical

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

Read Solution (Total 1)

Java Other Question

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
What is the output of the following program?

class Icecream
{
public void displayName(String s)
{
System.out.println(s+" "+"Icecream");
}
public void describe(String s)
{
System.out.println(s+" "+"Icecream: Ice cream is a sweetened frozen food typically eaten as a snack or dessert. ");
}
}

class Faloodeh extends Icecream
{
public void displayName(String s)
{
System.out.println(s+" "+"Faloodeh ");
}

public void describe(String s)
{
System.out.println(s+" "+"Faloodeh: Faloodeh is often served alongside Persian-style dairy-based ice cream ");
}
}

public class Test
{
public static void main(String arg[])
{
Icecream a = new Faloodeh();
Faloodeh b = (Faloodeh)a;
a.displayName("test");
b.displayName("test");
a.describe("test");
b.describe("test");
}
}

A. test Faloodeh: Faloodeh is often served alongside Persian-style dairy-based ice cream
test Faloodeh: Faloodeh is often served alongside Persian-style dairy-based ice cream
test Faloodeh
test Faloodeh

B. test Faloodeh
test Faloodeh
test Faloodeh: Faloodeh is often served alongside Persian-style dairy-based ice cream
test Faloodeh: Faloodeh is often served alongside Persian-style dairy-based ice cream

C. test Faloodeh
test Faloodeh: Faloodeh is often served alongside Persian-style dairy-based ice cream
test Faloodeh: Faloodeh is often served alongside Persian-style dairy-based ice cream
test Faloodeh

D. test Faloodeh: Faloodeh is often served alongside Persian-style dairy-based ice cream
test Faloodeh
test Faloodeh
test Faloodeh: Faloodeh is often served alongside Persian-style dairy-based ice cream