Telegram Group & Telegram Channel
What will be the output of the code?

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.



tg-me.com/topJavaQuizExplain/266
Create:
Last Update:

What will be the output of the code?

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

Share with your friend now:
tg-me.com/topJavaQuizExplain/266

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

For some time, Mr. Durov and a few dozen staffers had no fixed headquarters, but rather traveled the world, setting up shop in one city after another, he told the Journal in 2016. The company now has its operational base in Dubai, though it says it doesn’t keep servers there.Mr. Durov maintains a yearslong friendship from his VK days with actor and tech investor Jared Leto, with whom he shares an ascetic lifestyle that eschews meat and alcohol.

A Telegram spokesman declined to comment on the bond issue or the amount of the debt the company has due. The spokesman said Telegram’s equipment and bandwidth costs are growing because it has consistently posted more than 40% year-to-year growth in users.

telegram from us


Telegram Explanations “Top Java Quiz Questions”
FROM USA