t the correct answerPredict the output of the given Java Program. class Grandparent { public void show() { System.out.println("Grandparent::show() called"); } } class Parent extends Grandparent { public void show() { System.out.println("parent::show() called"); } } class Main { public static void main(String[] args) { Grandparent b = new Parent();; b.show(); } }OptionsParent::show() calledCompiler Errorgrandparent::show() calledException
Question
t the correct answerPredict the output of the given Java Program. class Grandparent { public void show() { System.out.println("Grandparent::show() called"); } } class Parent extends Grandparent { public void show() { System.out.println("parent::show() called"); } } class Main { public static void main(String[] args) { Grandparent b = new Parent();; b.show(); } }OptionsParent::show() calledCompiler Errorgrandparent::show() calledException
Solution
The output of the given Java program will be "Parent::show() called".
Here's the step by step explanation:
-
The Grandparent class has a method called show() which prints "Grandparent::show() called".
-
The Parent
Similar Questions
Select the correct answerWhat is the output of the following java program?class Parent { public final void show() { System.out.println("Parent::show() called"); }}class Child extends Parent { public void show() { System.out.println("Child::show() called"); }}public class Main { public static void main(String[] args) { Parent p = new Child();; p.show(); }}OptionsCompiler ErrorBase::show() calledDerived::show() calledException
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
Assuming that all the necessary imports are done, what will be the output of the following Java program? class parent { int a; } class child extends parent { int b; void display() { super.a = b + 1; System.out.println(b + " " + i); } } class inheritance { public static void main(String args[]) { child obj = new child(); obj.a=1; obj.b=2; obj.display(); }}Options3 32 22 3Compilation Error
Select the correct answerWhat is the output of the following Java program?class Parent { String name = "parent"; String message() { return "from parent"; }}class Child extends Parent { String name = "child"; String message() { return "from child"; }}public class Main { public static void main(String[] args) { Parent p = new Child(); System.out.println(p.name + " " + p.message()); }}Options"parent from parent""parent from child""child from parent""child from child"
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.