Knowee
Questions
Features
Study Tools

elect the correct answerPredict the output of the given Java Programs. class A {    public void Print() {        System.out.println("B's Print()");     }  }   class A extends B {    public void Print() {        System.out.println("A's Print()");      }  }   class C extends A {    public void Print() {        super.super.Print();        System.out.println("C's Print()");     }  }   public class Main {    public static void main(String[] args) {         C c = new C();         c.Print();      } }OptionsB's Print()C's Print()A's Print()Compiler Error

Question

elect the correct answerPredict the output of the given Java Programs. class A {    public void Print() {        System.out.println("B's Print()");     }  }   class A extends B {    public void Print() {        System.out.println("A's Print()");      }  }   class C extends A {    public void Print() {        super.super.Print();        System.out.println("C's Print()");     }  }   public class Main {    public static void main(String[] args) {         C c = new C();         c.Print();      } }OptionsB's Print()C's Print()A's Print()Compiler Error

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is Compiler Error.

In Java, you cannot directly access the methods of the grandparent class using the "super.super.method()" syntax. It's not allowed in Java. Therefore, the line "super.super.Print();" in class C will cause a compile-time error.

Similar Questions

What will be the output of the following code?class A {    void method() {        System.out.println("Class A");    }}class B extends A {    void method() {        super.method();        System.out.println("Class B");    }}public class Main {    public static void main(String[] args) {        B obj = new B();        obj.method();    }}

Select the correct answerWhat will be the output of the following Java program?class A { int i; void display() { System.out.println(i); }}class B extends A { int j; void display() { System.out.println(j); }}class inheritance_demo { public static void main(String args[]) { B obj = new B(); obj.i = 1; obj.j = 2; obj.display(); }}Options102Compilation Error

Output of following Java program?class Grandparent {    public void Print() {        System.out.println("Grandparent");    }         } class Parent extends Grandparent {        public void Print() {        System.out.println("Parent");    }} class Main{    public static void DoPrint( Grandparent o ) {        o.Print();       }    public static void main(String[] args) {        Grandparent a = new Grandparent();        Grandparent b = new Parent();        Parent c = new Parent();        DoPrint(a);        DoPrint(b);        DoPrint(c);    }}OptionsGrandparentGrandparentParentGrandparentParentParentGrandparentParentGrandparentCompiler Error

Analyze the following code carefully. Please select the one that applies.public class Test {  public static void main(String[] args) {    A a = new A();    a.print();  }}class A {  String s;  A(String s) {    this.s = s;  }void print() {    System.out.println(s);  }}

What is the output of this program? class A { public int i; private int j; } class B extends A { void display() { super.j = super.i + 1; System.out.println(super.i + " " + super.j); } } class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } }2 23 3Runtime ErrorCompilation Erro

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.