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 |
// Class A is declared in a file named A.java.
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 D is declared in a file named D.java.
package com.dan.chisholm.other;
import com.dan.chisholm.A;
public class D {
public static void main(String[] args) {
A a = new A();
a.m1(); // 1
a.m2(); // 2
a.m3(); // 3
a.m4(); // 4
}}
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. |
// Class A is declared in a file named A.java.
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 C is declared in a file named C.java.
package com.dan.chisholm.other;
import com.dan.chisholm.A;
public class C extends A {
public static void main(String[] args) {
C c = new C();
c.m1(); // 1
c.m2(); // 2
c.m3(); // 3
c.m4(); // 4
}}
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. |