Knowee
Questions
Features
Study Tools

Select the correct answerAssuming that all the necessary imports are done, what will be the output of the following Java code? class codetantra {     public int a;     public int b;     codetantra() {         a = 5;         b = 6; } }     class coding extends codetantra {     int i;  coding() {         super();     }  }     class inheritance {     public static void main(String args[]) {         coding obj = new coding();         System.out.println(obj.a + " " + obj.b);      } }Options6 55 6Runtime ErrorCompilation Error

Question

Select the correct answerAssuming that all the necessary imports are done, what will be the output of the following Java code? class codetantra {     public int a;     public int b;     codetantra() {         a = 5;         b = 6; } }     class coding extends codetantra {     int i;  coding() {         super();     }  }     class inheritance {     public static void main(String args[]) {         coding obj = new coding();         System.out.println(obj.a + " " + obj.b);      } }Options6 55 6Runtime ErrorCompilation Error

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

Solution

The correct answer is 5 6.

Here's the step by step explanation:

  1. The class codetantra has two public integer variables a and b. In the constructor of codetantra, a is assigned the value 5 and b is assigned the value 6.

  2. The class coding extends codetantra, which means it inherits the properties and methods of codetantra. Therefore, an object of coding will have access to variables a and b.

  3. In the main method of the inheritance class, an object obj of class coding is created.

  4. The println statement prints the values of a and b of the obj object. Since a and b are inherited from codetantra and their values are set to 5 and 6 respectively in the codetantra constructor, the output will be "5 6".

This problem has been solved

Similar Questions

Select the correct answerAssuming that the required imports are done, what will be the output of the following Java program?class string_class {    public static void main(String args[]) {       String obj = "I LIKE CODETANTRA";        System.out.println(obj.length());    }}Options1116917

Select the correct answerAssuming that all the necessary imports are done, what will be the output of the following Java code? class parent {  int x;     void display() {      System.out.println(x);     } }     class child extends parent {     int y;     void display() {         System.out.println(y);     } }     class method_overriding {     public static void main(String args[]) {          child obj = new child();         obj.x=4;         obj.y=5;            obj.display();          } }Options435Compilation 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

the correct answerAssuming that all the necessary imports are done, what will be the output of the following Java code? class ct {     public int x;     private int y; }     class uv extends ct {    void display() {        super.y = super.x + 1;        System.out.println(super.x + " " + super.y);     } }  class inheritance {    public static void main(String args[]) {         uv obj = new uv();         obj.x = 1;         obj.y = 2;            obj.display();          } }Options2 2Runtime Error3 3Compilation Error

Select the correct answerAssuming that the required imports are done, what will be the output of the following Java code?class rectangle {    int width;    int length;    int area;    void area() {        area = width*length;        System.out.println(area);    }}    class Output {    public static void main(String args[]) {         rectangle obj = new rectangle();        obj.width=5;        obj.length=6;        obj.area();    }}Options1301136

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.