❌ A. 10 ✅ B. 20 ❌ C. 30 ❌ D. Compilation error ❌ E. Runtime error ❌ F. None of the above
Explanation: The code defines a class MyClass with a private instance variable myVar, a constructor that initializes myVar, and getter and setter methods for myVar.
In the Main class, an object obj1 of MyClass is created with the value 10 passed as an argument to the constructor. Then, obj2 is assigned a reference to the same object as obj1. Next, the setMyVar() method is called on obj2 with a value of 20. Finally, the value of myVar in obj1 is printed.
Since obj1 and obj2 refer to the same object, calling setMyVar() on obj2 also changes the value of myVar in obj1. Therefore, the output will be 20.
❌ A. 10 ✅ B. 20 ❌ C. 30 ❌ D. Compilation error ❌ E. Runtime error ❌ F. None of the above
Explanation: The code defines a class MyClass with a private instance variable myVar, a constructor that initializes myVar, and getter and setter methods for myVar.
In the Main class, an object obj1 of MyClass is created with the value 10 passed as an argument to the constructor. Then, obj2 is assigned a reference to the same object as obj1. Next, the setMyVar() method is called on obj2 with a value of 20. Finally, the value of myVar in obj1 is printed.
Since obj1 and obj2 refer to the same object, calling setMyVar() on obj2 also changes the value of myVar in obj1. Therefore, the output will be 20.
Therefore, the correct answer is option 20.
BY Explanations “Top Java Quiz Questions”
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
The SSE was the first modern stock exchange to open in China, with trading commencing in 1990. It has now grown to become the largest stock exchange in Asia and the third-largest in the world by market capitalization, which stood at RMB 50.6 trillion (US$7.8 trillion) as of September 2021. Stocks (both A-shares and B-shares), bonds, funds, and derivatives are traded on the exchange. The SEE has two trading boards, the Main Board and the Science and Technology Innovation Board, the latter more commonly known as the STAR Market. The Main Board mainly hosts large, well-established Chinese companies and lists both A-shares and B-shares.
Tata Power whose core business is to generate, transmit and distribute electricity has made no money to investors in the last one decade. That is a big blunder considering it is one of the largest power generation companies in the country. One of the reasons is the company's huge debt levels which stood at ₹43,559 crore at the end of March 2021 compared to the company’s market capitalisation of ₹44,447 crore.