• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Java | Class and Object | Question 4

JAVA
class demo
{
    int a, b;
    
    demo()
    {
        a = 10;
        b = 20;
    }
    
    public void print()
    {
        System.out.println (\"a = \" + a + \" b = \" + b + \"\\n\");
    }
}

class Test
{

    public static void main(String[] args)
    {
        demo obj1 = new demo();
        demo obj2 = obj1;

        obj1.a += 1;
        obj1.b += 1;

        System.out.println (\"values of obj1 : \");
        obj1.print();
        System.out.println (\"values of obj2 : \");
        obj2.print();

    }
}

(A)

Compile error

(B)

values of obj1: 
a = 11 b = 21
values of obj2: 
a = 11 b = 21

(C)

values of obj1: 
a = 11 b = 21
values of obj2: 
a = 10 b = 20

(D)

values of obj1: 
a = 11 b = 20
values of obj2: 
a = 10 b = 21

(E)

Run time error

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments