Question: Part A: Given the following code: package com.dan.chisholm; public class A { public void m1() {System.out.print(A.m1, ); } protected void m2() {System.out.print(A.m2, );} private void
Part A:
Given the following code:
package com.dan.chisholm;
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
Part B:
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
Part C:
class GRC10 {
public static void main (String[] s) {
System.out.print(s[1] + s[2] + s[3]);
}}
java GRC10 A B C D E F
What is the result of attempting to compile and run the program using the specified command line?
a. Prints: ABC
b. Prints: BCD
c. Prints: CDE
d. Prints: A B C
e. Prints: B C D
f. Prints: C D E
g. Compile-time error
h. Run-time error
i. None of the above
Part D:
class MCZ11 {
public static void main (String[] args) {
char a = '\c'; // 1
char b = ' '; // 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
Part E:
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? Choose 2!
a. 1
b. 2
c. 3
d. 4
e. 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
