tut01_sol - EE3206/EE5805 Java Programming & Application...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
EE3206/EE5805 Java Programming & Application Tutorial 1 - Solution Q1 a) It compiles, and x becomes 1 (byte). b) It compiles, and x becomes 127 (byte). c) Compilation error: “possible loss of precision; found : int; required : byte”. The byte primitive type stores values from -128 to 127. The value 128 cannot be stored in a byte variable. d) Compilation error: “possible loss of precision; found : int; required : char”. Though x is of type char, the expression (x + 1) evaluates to type int, and Java does not allow assignment an int value to a char variable without explicit casting. e) It compiles, and x becomes '1' (char). Initialization is sometimes different from assignment. Here the compiler computes '0' + 1 at compilation time to get '1', and initializes variable x to '1'. f) Compilation error: “possible loss of precision; found : int; required : char”. Here the expression (y + 1) is evaluated at run-time, and the result is of int type. Assigning an int value to a char variable without explicit casting is forbidden. g)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/11/2011 for the course EE 3206 taught by Professor Cwting during the Spring '07 term at City University of Hong Kong.

Page1 / 3

tut01_sol - EE3206/EE5805 Java Programming & Application...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online