What is the result?

Given:

21. class Money {
22. private String country = “Canada”;
23. public String getC() { return country; }
24. }
25. class Yen extends Money {
26. public String getC() { return super.country; }
27. }
28. public class Euro extends Money {
29. public String getC(int x) { return super.getC(); }
30. public static void main(String[] args) {
31. System.out.print(new Yen().getC() + ” ” + new Euro().getC());
32. }
33. }

What is the result?

Given:

21. class Money {
22. private String country = “Canada”;
23. public String getC() { return country; }
24. }
25. class Yen extends Money {
26. public String getC() { return super.country; }
27. }
28. public class Euro extends Money {
29. public String getC(int x) { return super.getC(); }
30. public static void main(String[] args) {
31. System.out.print(new Yen().getC() + ” ” + new Euro().getC());
32. }
33. }

What is the result?

A.
Canada

B.
null Canada

C.
Canada null

D.
Canada Canada

E.
Compilation fails due to an error on line 26.

F.
Compilation fails due to an error on line 29.

Explanation:
Yen.java:26: country has private access in Money
public String getC() { return super.country; }
^
1 error

The field Money.country is not visible (Money’s private var)



Leave a Reply 0

Your email address will not be published. Required fields are marked *