单选题:Given:
Given:
ClassOne.java
```Java
package com.abc.pkg1;
public class ClassOne {
private char var = ‘a’;
char getVar() {return var;}
}
```
ClassTest.java
```Java
package com.abc.pkg2;
import com.abc.pkg1.ClassOne;
public class ClassTest extends ClassOne {
public static void main(String[]args) {
char a = new ClassOne().getVar();
char b = new ClassTest().getVar();
}
}
```
What is the result? @[A](2)
A. Compilation will fail.
B. Compilation succeeds and no exceptions are thrown.
C. Compilation succeeds but an exception is thrown at line 5 in ClassTest.java.
D. Compilation succeeds but an exception is thrown at line 6 in ClassTest.java.
A.Compilation will fail.
B.Compilation succeeds and no exceptions are thrown.
C.Compilation succeeds but an exception is thrown at line 5 in ClassTest.java.
D.Compilation succeeds but an exception is thrown at line 6 in ClassTest.java.
答案:A
ClassOne.java
```Java
package com.abc.pkg1;
public class ClassOne {
private char var = ‘a’;
char getVar() {return var;}
}
```
ClassTest.java
```Java
package com.abc.pkg2;
import com.abc.pkg1.ClassOne;
public class ClassTest extends ClassOne {
public static void main(String[]args) {
char a = new ClassOne().getVar();
char b = new ClassTest().getVar();
}
}
```
What is the result? @[A](2)
A. Compilation will fail.
B. Compilation succeeds and no exceptions are thrown.
C. Compilation succeeds but an exception is thrown at line 5 in ClassTest.java.
D. Compilation succeeds but an exception is thrown at line 6 in ClassTest.java.
A.Compilation will fail.
B.Compilation succeeds and no exceptions are thrown.
C.Compilation succeeds but an exception is thrown at line 5 in ClassTest.java.
D.Compilation succeeds but an exception is thrown at line 6 in ClassTest.java.
答案:A