Assume that country is set for each class. Given: 10. public class Money { 11. private String country, name; 12. public getCountry() { return country; } 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.)

  1. Euro returns correct values

  2. An exception is thrown at runtime.

  3. Yen and Euro both return correct values

  4. Compilation fails because of an error at line 25.


Correct Option: A,D

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) Euro returns correct values - This option is correct. In the Euro class, the getCountry(String timeZone) method calls the super.getCountry() method, which is inherited from the Money class. Since the getCountry() method in the Money class does not take any arguments and simply returns the value of the country field, this method will return the correct value.

Option B) An exception is thrown at runtime - This option is not mentioned in the given code snippet. Therefore, it is incorrect.

Option C) Yen and Euro both return correct values - This option is incorrect. The Yen class overrides the getCountry() method and returns super.country. However, the super.country expression is incorrect. The country field is private in the Money class and cannot be accessed directly by the Yen class. Therefore, the Yen class will not return the correct value.

Option D) Compilation fails because of an error at line 25 - This option is correct. The Yen class attempts to access the country field of the Money class using super.country, but the country field is private and cannot be accessed from a subclass. This will result in a compilation error.

The correct answers are A and D.

Find more quizzes: