Knowee
Questions
Features
Study Tools

elect the correct answerWhat will be the output of the following Java program? class surface_area     {        int base;        int length; int height;        double volume;        surface_area()         {           base=12;           length=7;        }        void volume()         {             volume = 0.5*base*height*length;        }     }        class cons_method     {        public static void main(String args[])        {            surface_area obj = new surface_area();            obj.volume();            System.out.println(obj.volume);                }     }Options841.00.0error

Question

elect the correct answerWhat will be the output of the following Java program? class surface_area     {        int base;        int length; int height;        double volume;        surface_area()         {           base=12;           length=7;        }        void volume()         {             volume = 0.5baseheight*length;        }     }        class cons_method     {        public static void main(String args[])        {            surface_area obj = new surface_area();            obj.volume();            System.out.println(obj.volume);                }     }Options841.00.0error

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

Solution

The output of the program will be 0.0. This is because while the 'base' and 'length' variables are initialized in the constructor of the 'surface_area' class, the 'height' variable is not. Therefore, its default value remains 0. When calculating the volume, the expression 0.5 * base * height * length becomes 0 because the 'height' is 0. Hence, the volume printed is 0.0.

Similar Questions

Select the correct answerWhat will be the output of the following Java code?  class Area {    public static void main(String args[])     {          double radii, pi, area;       radii = 6.6;       pi = 3.14;       area = pi * radii * radii;       System.out.println(area);    }   }Options136136.7784136.77136.7760000

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

elect the correct answerWhat will be the output of the following Java code?class rhombus    {        int d1;        int d2;        int area;    public void area()        {            area = (d1*d2)/2;            System.out.println(area);        }    }    class Output    {        public static void main(String args[])        {            rhombus obj = new rhombus();            obj.d1=8;            obj.d2=2;            obj.area();        }    }OptionsRun time error168Compilation error

Select the correct answerWhat will be the output of the following Java program?class box   {    int height;    int radius;    double pie;    double volume;    void volume(int height, int radius, double pie)     {       volume = pie*(radius*radius)*height/3;    }   }     class Prameterized_method  {    public static void main(String args[])    {      box obj = new box();      obj.height = 52;      obj.radius = 46;      obj.pie = 3.14285714286;      obj.volume(45,89,90);      System.out.println(obj.volume);         }    }Options1.069335E70.178501A80.178409D21.069788F6

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

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.