Ask Question
6 February, 11:56

Given public class Fishing { byte b1 = 4; int i1 = 123456; long L1 = (long) i1; / /Line A short s2 = (short) i1; / /Line B byte b2 = (byte) i1; / /Line C int i2 = (int) 123.456; / /Line D byte b3 = b1 + 7; / /Line E } Which lines WILL NOT compile? (Choose all that apply)

+1
Answers (1)
  1. 6 February, 13:05
    0
    Line E.

    Explanation:

    The given program is as follows:

    public class Fishing {

    byte b1 = 4; int i1 = 123456; long L1 = (long) i1; / /Line A

    short s2 = (short) i1; / /Line B

    byte b2 = (byte) i1; / /Line C

    int i2 = (int) 123.456; / /Line D

    byte b3 = b1 + 7; / /Line E

    }

    In the above code Line E will not compile and give following compilation error:

    error: incompatible types: possible lossy conversion from int to byte

    This error is coming because in Java b1 + 7 will be interpreted as int variable expression. Therefore in order to make code of Line E work the expression should be type casted as byte.

    The correct code will be as follows:

    public class Fishing {

    byte b1 = 4; int i1 = 123456; long L1 = (long) i1; / /Line A

    short s2 = (short) i1; / /Line B

    byte b2 = (byte) i1; / /Line C

    int i2 = (int) 123.456; / /Line D

    byte b3 = (byte) (b1 + 7); / /Line E

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given public class Fishing { byte b1 = 4; int i1 = 123456; long L1 = (long) i1; / /Line A short s2 = (short) i1; / /Line B byte b2 = (byte) ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers