Knowee
Questions
Features
Study Tools

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

Question

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

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

Solution

Compiler Error

Similar Questions

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

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"

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

elect the correct answerWhat will be the output of the following Java program? class parent { int a; public void display() { System.out.println(a); } } class child extends parent { int b; public void display() { System.out.println(b); } } class Dynamic_dispatch { public static void main(String args[]) { child obj2 = new child(); obj2.a = 2; obj2.b = 4; parent r; r = obj2; r.display(); } }Options6428

Observe the below code :class Parent  {      public void display() {                System.out.println("Parent");      }}class Child extends Parent  {      public void display() {                System.out.println("Child");      }}public class Main  {       public static void main(String args[ ])   {               Parent p =   ;               Child  c = ;               p.display();  c.display();       }}Fill the code accordingly, so that you get the output asChildChild.

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.