0 votes
358 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 88 views
asked Jul 20, 2022 in JAVA by Doubtly (98.9k points)
0 votes
1 answer 2.8k views
0 votes
1 answer 136 views
asked Jul 20, 2022 in JAVA by Doubtly (98.9k points)
0 votes
1 answer 144 views
asked Jul 20, 2022 in JAVA by Doubtly (98.9k points)
0 votes
1 answer 205 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

537 users

...