Question
Part A: What happens when you attempt to compile and execute the following application? 1. class XXX { 2. public static void main(String[] args) {
Part A:
What happens when you attempt to compile and execute the following application?
1. class XXX {
2. public static void main(String[] args) {
3. String s1 = "abcde";
4. String s2 = "abcde";
5. s1.toUpperCase();
6. if (s1 == s2)
7. System.out.println("YES");
8. else
9. System.out.println("NO");
10. }
11. }
a. Compilation error
b. Prints YES
c. Prints NO
d. Runtime Exception
Part B:
Which of the following statements are true? Choose 3
a. A value can not be assigned to a final field more than once.
b. A value can be assigned to a final field at any time or not at all.
c. Only static variables can be declared final.
d. A compile-time error is thrown if a blank final instance variable is not assigned a value before the end of each constructor.
e. A field can not be declared both final and volatile.
Part C:
class A {
public static void main(String[] args) {
int[][] a1 = {{1,2},{3,4,5},{6,7,8,9},{}};
System.out.print(a1.length);
}
}
What is the result of attempting to compile and run the program?
a. Prints: 0
b. Prints: 3
c. Prints: 4
d. Prints: 9
e. Prints: 10
f. Prints: 11
g. Compile-time error
h. Run-time error
i. None of the above
Part D:
Which of these lists contains at least one word that is not a Java keyword?
a. interface, static, void, catch, final
b. char, strictfp, finally, long, volatile
c. native, super, class, float, while
d. const, for, new, switch, import
e. continue, finalize, goto, package, synchronized
f. None of the above
Part E:
class A {
static int m(int i) {
System.out.print(i + ", ");
return i;
}
public static void main(String s[]) {
int i = 1;
m(m(++i) - m(i++) + m(-i) * m(~i));
}
}
What is the result of attempting to compile and run the above program?
a. Prints: 2, 2, -3, -4, 8,
b. Prints: 2, 2, -3, -4, 12,
c. Prints: 2, 3, -3, -4, 7,
d. Prints: 1, 1, 1, 1, 0,
e. Prints: 2, 2, -2, -2, 4,
f. Prints: 2, 3, -2, -2, 3,
g. Prints: -1, -2, 2, 2, 0,
h. Run-time error
i. Compile-time error
j. None of the above
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started