Home » JAVA Programming » Object & Classes » Question
  1. What is the output of this program?

    class box_Shape
    {
    int width;
    int height;
    int length;
    }
    public class mainclass
    {
    public static void main(String args[])
    {
    box_Shape obj1 = new box_Shape();
    box_Shape obj2 = new box_Shape();
    obj1.height = 3;
    obj1.length = 4;
    obj1.width = 6;
    obj2 = obj1;
    System.out.println(obj2.height);
    }
    }
    1. 3
    2. 2
    3. 1
    4. Runtime error
    5. Garbage value
Correct Option: A

When we assign an object to another object of same type, all the elements of right side object gets copied to object on left side of equal to, =, operator.
output: 3



Your comments will be displayed only after manual approval.