adplus-dvertising
frame-decoration

Question

What is the output of this program?
    class box 
    {
        int width;
        int height;
        int length;
    } 
    class mainclass 
    {
        public static void main(String args[]) 
        {        
            box obj1 = new box();
            box obj2 = new box();
            obj1.height = 1;
            obj1.length = 2;
            obj1.width = 1;
            obj2 = obj1;
            System.out.println(obj2.height);
        } 
    }

a.

1

b.

2

c.

Runtime error

d.

Garbage value

Answer: (a).1

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?

Similar Questions

Discover Related MCQs

Q. What is the return type of a method that does not return any value?

Q. What is the process of defining more than one method in a class differentiated by method signature?

Q. Which of the following is a method having same name as that of it’s class?

Q. Which method can be defined only once in a program?

Q. Which keyword is used by the method to refer to the object that invoked it?

Q. Which of the following is a method having same name as that of its class?

Q. Which operator is used by Java run time implementations to free the memory of an object when it is no longer needed?

Q. Which function is used to perform some action when the object is to be destroyed?

Q. What is true about private constructor?

Q. What would be the behaviour if this() and super() used in a method?

Q. What is false about constructor?

Q. What is true about Class.getInstance()?

Q. What is true about constructor?

Q. Abstract class cannot have a constructor.

Q. What is true about protected constructor?

Q. What is not the use of “this” keyword in Java?

Q. What would be the behaviour if one parameterized constructor is explicitly defined?

Q. What would be behaviour if the constructor has a return type?

Q. Which of the following has the highest memory requirement?

Q. Where is a new object allocated memory?