What will be the output of the following Java code?

class area 
   {
       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);        
       } 
   }

a) 0 0
b) 5 6
c) 6 5
d) 5 5

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

  1. c
    Explanation: this keyword can be used inside any method to refer to the current object. this is always a reference to the object on which the method was invoked.
    output:
    $ javac Output.java
    $ java Output
    6 5

Leave a Comment