What will be the output of the following Java program?

class area 
    {
        int width;
        int length;
        int volume;
        area() 
        {
           width=5;
           length=6;
        }
        void volume() 
        {
             volume = width*length*height;
        } 
    }    
    class cons_method 
    {
        public static void main(String args[])
        {
            area obj = new area();
            obj.volume();
            System.out.println(obj.volume);        
        } 
    }

a) 0
b) 1
c) 30
d) error

1 thought on “What will be the output of the following Java program?”

  1. d
    Explanation: Variable height is not defined.
    output:
    $ javac cons_method.java
    $ java cons_method
    error: cannot find symbol height

Leave a Comment