Knowee
Questions
Features
Study Tools

correct answerWhat will be the output of the following Java code? class main {    public int x;    protected int y; }     class derived extends main {     int y;     void display() {         super.y = 5;         System.out.println(x + " " + y);     } }     class Output {     public static void main(String args[]) {          derived obj = new derived();         obj.x=2;         obj.y=3;            obj.display();          } }Options2 32 53 25 2

Question

correct answerWhat will be the output of the following Java code? class main {    public int x;    protected int y; }     class derived extends main {     int y;     void display() {         super.y = 5;         System.out.println(x + " " + y);     } }     class Output {     public static void main(String args[]) {          derived obj = new derived();         obj.x=2;         obj.y=3;            obj.display();          } }Options2 32 53 25 2

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

Solution

The output of the Java code will be "2 3".

Here's the step by step explanation:

  1. An object obj of class derived is created in the main method of the Output class.

  2. The x and y variables of the obj

Similar Questions

What will be the output of the following code?This question is required.*class Base {public void display() {System.out.println("Base");}}class Derived extends Base {public void display() {System.out.println("Derived");}}public class Main {public static void main(String[] args) {Base b = new Derived();b.display();}}

Select the correct answerWhat will be the output of the following Java program? final class base     {         int a;    }        class derived extends base    {        int b;        System.out.println(b + " " + a);      }        class inheritance     {        public static void main(String args[])        {            derived obj = new derived();            obj.display();             }   }OptionsRuntime Error3 32 2Compilation Error

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

e correct answerWhat will be the output of the following Java code?  class Codetantra  {    final public int output(int x, int y) { return 1; }   }   class Program extends Codetantra   {     public int output(int x, int y) { return 2; }   }    public class result   {    public static void main(String args[])     {       Program object = new Program();       System.out.print("y is " + y.output(0, 1));      }   }

class Base { public void Print() { System.out.println("Base"); }} class Derived extends Base { public void Print() { System.out.println("Derived"); }} class InhDriver { public static void printMsg(Base ob) { ob.Print(); } public static void main(String[] args) { Base x = new Base(); Base y = new Derived(); Derived z = new Derived(); printMsg(x); printMsg(y); printMsg(z); }}

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.