Page 94
[ Team LiB ] Review Questions 3.1 Given char c = ‘A’; What is the simplest way to convert the character value in c into an int? Select the one correct answer. a. int i = c; b. int i = (int) c; c. int i = Character.getNumericValue(c); 3.2 What will be the result of attempting to compile and run the following class? public class Assignment { public static void main(String[] args) { int a, b, c; b = 10; a = b = c = 20; System.out.println(a); } } Select the one correct answer. a. The code will fail to compile, since the compiler will recognize that the variable c in the assignment statement a = b = c = 20; has not been initialized. b. c. d. The code will fail to compile because the assignment statement a = b = c = 20; is illegal. The code will compile correctly and will display 10 when run. The code will compile correctly and will display 20 when run. 3.3 What will be the result of attempting to compile and run the following program? public class MyClass { public static void main(String[] args) { String a, b, c; c = new String(”mouse”); a = new String(”cat”); b = a; a = new String(”dog”); c = b; System.out.println(c); } Page 96
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services