Which of the following statements is correct? (Choose one.)
A. Only primitives are converted automatically; to change the type of an object
reference, you
have to do a cast.
B. Only object references are converted automatically; to change the type of a primitive,
you
have to do a cast.
C. Arithmetic promotion of object references requires explicit casting.
D. Both primitives and object references can be both converted and cast.
E. Casting of numeric types may require a runtime check. ** Answ** d
Which one line in the following code will not compile?
1. byte b = 5;
2. char c = '5';
3. short s = 55;
4. int i = 555;
5. float f = 555.5f;
6. b = s;
7. i = c;
8. if (f > b)
9. f = i;
A. Line 1
B. Line 2
C. Line 3
D. Line 4
E. Line 5
F. Line 6
G. Line 7
H. Line 8
I. Line 9 ** Answ** f
Will the following code compile?
1. byte b = 2;
2. byte b1 = 3;
3. b = b * b1;
A. Yes
B. No ** Answ** b
In the following code, what are the possible types for variable result? (Choose the most
complete
true answer.)
, 1. byte b = 11;
2. short s = 13;
3. result = b * ++s;
A. byte, short, int, long, float, double
B. boolean, byte, short, char, int, long, float, double
C. byte, short, char, int, long, float, double
D. byte, short, char
E. int, long, float, double ** Answ** e
Consider the following class:
1. class Cruncher {
2. void crunch(int i) {
3. System.out.println("int version");
4. }
5. void crunch(String s) {
6. System.out.println("String version");
7. }
8.
9. public static void main(String args[]) {
10. Cruncher crun = new Cruncher();
11. char ch = 'p';
12. crun.crunch(ch);
13. }
14. }
Which of the following statements is true? (Choose one.)
A. Line 5 will not compile, because void methods cannot be overridden.
B. Line 12 will not compile, because no version of crunch() takes a char argument.
C. The code will compile but will throw an exception at line 12.
D. The code will compile and produce the following output: int version.
E. The code will compile and produce the following output: String version. ** Answ**
d
Which of the following statements is true? (Choose one.)
A. Object references can be converted in assignments but not in method calls.
B. Object references can be converted in method calls but not in assignments.
C. Object references can be converted in both method calls and assignments, but the
rules
governing these conversions are very different.
D. Object references can be converted in both method calls and assignments, and the
rules
governing these conversions are identical.
E. Object references can never be converted. ** Answ** d
Consider the following code. Which line will not compile?
1. Object ob = new Object();
2. String[] stringarr = new String[50];