Ask 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) 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)

+3
Answers (1)
  1. 13 March, 10:06
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers