0 votes
393 views
in JAVA by (98.9k points)
edited

What will be the error in the following Java code?

    byte b = 50;
    b = b * 50;

a) b cannot contain value 50
b) b cannot contain value 100, limited by its range
c) No error in this code
d) * operator has converted b * 50 into int, which can not be converted to byte without casting

1 Answer

0 votes
by (98.9k points)
edited
Answer: d
Explanation: While evaluating an expression containing int, bytes or shorts, the whole expression is converted to int then evaluated and the result is also of type int.

Related questions

0 votes
1 answer 105 views
asked Jul 20, 2022 in JAVA by Doubtly (98.9k points)
0 votes
1 answer 2.8k views
0 votes
1 answer 160 views
asked Jul 20, 2022 in JAVA by Doubtly (98.9k points)
0 votes
1 answer 164 views
asked Jul 20, 2022 in JAVA by Doubtly (98.9k points)
0 votes
1 answer 290 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

561 users

...