Question 8
Assume that country is set for each class.
Given:
10. public class Money {
11. private String country, name;
12. public getCountry() { return country; } //问题一:奇怪,怎么没有标明返回类型(String或者什么的)呢?程序有错吧
13.}
and:
24. class Yen extends Money {
25. public String getCountry() { return super.country; }
26. }
27.
28. class Euro extends Money {
29. public String getCountry(String timeZone) {
30. return super.getCountry();
31. }
32. }
Which two are correct? (Choose two.)
A. Yen returns correct values.
B. Euro returns correct values. //问题二:怎么会正确呢?super.getCountry()都没有标明返回类型,而Euro里却要求返回一个String,奇了怪了!还有A为什么不正确!!!也就是问题三:
C. An exception is thrown at runtime.
D. Yen and Euro both return correct values.
E. Compilation fails because of an error at line 25. //问题三:怎么错了?
F. Compilation fails because of an error at line 30.
Answer: BE
谢谢
Assume that country is set for each class.
Given:
10. public class Money {
11. private String country, name;
12. public getCountry() { return country; } //问题一:奇怪,怎么没有标明返回类型(String或者什么的)呢?程序有错吧
13.}
and:
24. class Yen extends Money {
25. public String getCountry() { return super.country; }
26. }
27.
28. class Euro extends Money {
29. public String getCountry(String timeZone) {
30. return super.getCountry();
31. }
32. }
Which two are correct? (Choose two.)
A. Yen returns correct values.
B. Euro returns correct values. //问题二:怎么会正确呢?super.getCountry()都没有标明返回类型,而Euro里却要求返回一个String,奇了怪了!还有A为什么不正确!!!也就是问题三:
C. An exception is thrown at runtime.
D. Yen and Euro both return correct values.
E. Compilation fails because of an error at line 25. //问题三:怎么错了?
F. Compilation fails because of an error at line 30.
Answer: BE
谢谢
Money.java:3: 方法声明无效;需要返回类型
public getCountry() { return country; } //问题一:奇怪,怎么没有标明返回类型(String或者什么的)呢?程序有错吧
^
Money.java:14: 需要 '}'
}
^
2 错误揣摩题意: 我想应该是这样的: 每个类的 country 变量都赋予了不同的值; 各选项 correct value 应该是在运行时哪个类的 getCountry() 返回的是自己的 country 值,而不是父类的 country ?
2,如上
3,country私有,不能被子类访问到