Write down the following program in Java.
a. Class Color has got the method whatIsYourColor().
b. Classes Red, Green and White inherits the Color class
c. These classes override the method whatIsYourColor ()
d. Also, these sub-classes have a special method called whatDoYouDenote(), which is not available in the Color class.
e. When the method whatIsYourColor () is invoked on the specific child object, then the output should be as follows:
i. Red:whatIsYourColor () -> "Red"
ii. Green: whatIsYourColor () -> "Green"
iii. White:whatIsYourColor () -> "White"
f. When the method whatDoYouDenote () is invoked on the specific child object, then the output should be as follows:
i. Red:whatDoYouDenote () -> "Sacrifice"
ii. Green: whatDoYouDenote () -> "Prosperity"
iii. White:whatDoYouDenote () -> "Peace
Answers
Answer:
Write down the following program in Java.
a. Class Color has got the method whatIsYourColor().
b. Classes Red, Green and White inherits the Color class
c. These classes override the method whatIsYourColor ()
d. Also, these sub-classes have a special method called whatDoYouDenote(), which is not available in the Color class.
e. When the method whatIsYourColor () is invoked on the specific child object, then the output should be as follows:
i. Red:whatIsYourColor () -> "Red"
ii. Green: whatIsYourColor () -> "Green"
iii. White:whatIsYourColor () -> "White"
f. When the method whatDoYouDenote () is invoked on the specific child object, then the output should be as follows:
i. Red:whatDoYouDenote () -> "Sacrifice"
ii. Green: whatDoYouDenote () -> "Prosperity"
iii. White:whatDoYouDenote () -> "Peace