Answer Key to Understanding Inheritance in Java Please see the ...

31 downloads 44099 Views 18KB Size Report
Please see the following sample answers to the activity questions for the ... Solution: The apple class (Apple.java) inherits from the food class (Food.java). 2.
Answer Key to Understanding Inheritance in Java

Please see the following sample answers to the activity questions for the “Understanding Inheritance in Java” activity. 1. Which classes represent an inheritance relationship, and what is this relationship? Solution: The apple class (Apple.java) inherits from the food class (Food.java). 2. What method must be used to create the constructor for the Apple class? Solution: The constructor for the Apple class uses the Super() method to create a new Apple object. 3. What class keyword is used to denote that inheritance exists in java between classes? Solution: “extends” is used to denote that a class is inheriting from another class. For example, the Apple.java class has the following on the first line: public class Apple extends Food { This class declaration denotes that Apple inherits from Food.

Saylor URL: www.saylor.org/cs102 Sub-subunit 2.2.2

The Saylor Foundation

Saylor.org Page 1 of 1