Question 1 :
public class A { public void m1() {System.out.print("A.m1, ");} protected void m2() {System.out.print("A.m2, ");} private void m3() {System.out.print("A.m3, ");} void m4() {System.out.print("A.m4, ");}}
class B { public static void main(String[] args) {A a = new A();
a.m1(); // 1
a.m2(); // 2
a.m3(); // 3
a.m4(); // 4
}}
Assume that the code appears in a single file named A.java. What is the result of attempting to compile and run the program?
|
a. |
Prints: A.m1, A.m2, A.m3, A.m4, |
|
b. |
Compile-time error at 1. |
|
c. |
Compile-time error at 2. |
|
d. |
Compile-time error at 3. |
|
e. |
Compile-time error at 4. |
|
f. |
None of the above |
Question 2
class GFM11{ public static void main (String[] args) {int x,y,z;
System.out.println(x+y+z);
}}
What is the result of attempting to compile and run the program?
|
a. |
Prints nothing. |
|
b. |
Prints an undefined value. |
|
c. |
Prints: null |
|
d. |
Prints: 0 |
|
e. |
Run-time error |
|
f. |
Compile-time error |
|
g. |
None of the above |
Question 3
class MCZ11 { public static void main (String[] args) {char a = '\c'; // 1
char b = '\r'; // 2
char c = '\"'; // 3
char d = '\b'; // 4
char e = '\''; // 5
}}
A compile-time error is generated at which line?
|
a. |
1 |
|
b. |
2 |
|
c. |
3 |
|
d. |
4 |
|
e. |
5 |
|
f. |
None of the above |
Question 4
class MWC101 { public static void main(String[] args) {int[] a1 = new int[]; // 1
int a2[] = new int[5]; // 2
int[] a3 = new int[]{1,2}; // 3 int []a4 = {1,2}; // 4 int[] a5 = new int[5]{1,2,3,4,5}; // 5}}
Compile-time errors are generated at which lines?
|
a. |
1 |
|
b. |
2 |
|
c. |
3 |
|
d. |
4 |
|
e. |
5 |
Question 5
class A {A(int i) {}} // 1class B extends A {} // 2
Which of the following statements are true?
|
a. |
The compiler attempts to create a default constructor for class A. |
|
b. |
The compiler attempts to create a default constructor for class B. |
|
c. |
Compile-time error at 1. |
|
d. |
Compile-time error at 2. |
Question 6
Which of the following statements are true?
|
a. |
A constructor can invoke another constructor of the same class using the alternate constructor invocation, "this(argumentListopt);". |
|
b. |
A constructor can invoke itself using the alternate constructor invocation, "this(argumentListopt);". |
|
c. |
The alternate constructor invocation, "this(argumentListopt);", can legally appear anywhere in the constructor body. |
|
d. |
A constructor can invoke the constructor of the direct superclass using the superclass constructor invocation, "super(argumentListopt);". |
|
e. |
The number of constructor invocations that may appear in any constructor body can equal but not exceed the number of alternate constructors declared in the same class. |
|
f. |
A constructor is not permitted to throw an exception. |
Question 7
class A {A() throws Exception {}} // 1class B extends A {B() throws Exception {}} // 2class C extends A {C() {}} // 3
Which of the following statements are true?
|
a. |
class A extends Object. |
|
b. |
Compile-time error at 1. |
|
c. |
Compile-time error at 2. |
|
d. |
Compile-time error at 3. |
Question 8
Which of the following modifiers can be applied to a constructor?
|
a. |
private |
|
b. |
abstract |
|
c. |
final |
|
d. |
volatile |
|
e. |
native |
|
f. |
None of the above. |
Question 9
Which of the following modifiers can be applied to the declaration of a field?
|
a. |
abstract |
|
b. |
final |
|
c. |
private |
|
d. |
protected |
|
e. |
public |
Question 10
Which of the following modifiers can not be applied to a method?
|
a. |
abstract |
|
b. |
private |
|
c. |
protected |
|
d. |
public |
|
e. |
volatile |
|
f. |
None of the above. |