Telegram Group & Telegram Channel
What is the output of the following code?

3: byte a = 40, b = 50;
4: byte sum = (byte) a + b;
5: System.out.println(sum);


A. 40
B. 50
C. 90
D. The code will not compile because of line 4.
E. An undefined value

Explanation:
Line 4 generates a possible loss of precision compiler error. The cast operator has the highest precedence, so it is evaluated first, casting a to a byte. Then, the addition is evaluated, causing both a and b to be promoted to int values. The value 90 is an int and cannot be assigned to the byte sum without an explicit cast, so the code does not compile. The code could be corrected with parentheses around (a + b), in which case option C would be the correct answer.



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

What is the output of the following code?


3: byte a = 40, b = 50;
4: byte sum = (byte) a + b;
5: System.out.println(sum);


A. 40
B. 50
C. 90
D. The code will not compile because of line 4.
E. An undefined value

Explanation:
Line 4 generates a possible loss of precision compiler error. The cast operator has the highest precedence, so it is evaluated first, casting a to a byte. Then, the addition is evaluated, causing both a and b to be promoted to int values. The value 90 is an int and cannot be assigned to the byte sum without an explicit cast, so the code does not compile. The code could be corrected with parentheses around (a + b), in which case option C would be the correct answer.

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/38

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

Telegram announces Anonymous Admins

The cloud-based messaging platform is also adding Anonymous Group Admins feature. As per Telegram, this feature is being introduced for safer protests. As per the Telegram blog post, users can “Toggle Remain Anonymous in Admin rights to enable Batman mode. The anonymized admin will be hidden in the list of group members, and their messages in the chat will be signed with the group name, similar to channel posts.”

The messaging service and social-media platform owes creditors roughly $700 million by the end of April, according to people briefed on the company’s plans and loan documents viewed by The Wall Street Journal. At the same time, Telegram Group Inc. must cover rising equipment and bandwidth expenses because of its rapid growth, despite going years without attempting to generate revenue.

telegram from br


Telegram Explanations “Top Java Quiz Questions”
FROM USA