Knowee
Questions
Features
Study Tools

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

Question

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

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

Solution

The output of the given Java code will be 30.

Here's the step by step explanation:

  1. A rectangle object named 'obj' is created in the main method of the Output class.
  2. The width of 'obj' is set to 5.
  3. The length of 'obj' is set to 6.
  4. The area method of 'obj' is called. This method calculates the area by multiplying the width and length (5*6), assigns the result to the 'area' variable, and then prints the value of 'area'.

So, the output will be 30.

This problem has been solved

Similar Questions

Select the correct answerWhat will be the output of the following Java code?class rectangle { int width; int length; int area; void area(int width, int length) { this.width = width; this.length = length; }  } class Output { public static void main(String args[]) { area obj = new area(); obj.area(5 , 6); System.out.println(obj.length + " " + obj.width); } }Options6 55 630 00 30

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 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

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

Select the correct answerWhat will be the output of the following Java program? class shape {  int breadth;  int height;  int area;  void area()  {   area = 1/2 * breadth * height;  }   void area(int x)  {   area = x;  }  }  class triangle  {  public static void  main(String args[])  {   shape obj = new shape();   obj.breadth = 4;   obj.height = 4;   obj.area(4);    System.out.println(obj.area);   }  }Options04816

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.