Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another. With the use of inheritance the information is made manageable in a hierarchical order. Inheritance is an OOP feature that allows you to develop a class once and then reuse that code over and over as the basis of new classes. The class whose functionality is inherited is called a base class or parent class. The class that inherits the functionality is called a derived class or child class. A derived class can also define additional features that make it different from the base class.
Inheritance | Abstract Classes | Polymorphism | Review
Java inheritance is not about a large sum of money that you beloved, rich aunt has left you in her will. Inheritance is a Java feature that is immensley valuable because it allows objects fromone class to inherit the features of another class.
Review the following terms:
After viewing the object-orientated programming terminology, complete the Object-Orientated Programming Terminology Worksheet in itsLearning.
Directions: Draw a UML diagram for one of the following topics (super class): Animals, Plants, School. For the superclass, you must list two states and two behaviors. For each of the sub classes (and sub classes of the sub classes), list one additional state and one additional behavior. Make sure you clearly label which is state and which is behavior.
Submit your completed UML Diagram to the itsLearning assignment.
Directions: Describe in your own words:
Be sure to respond to two of your classmates.
Directions: Download the Inheritance Worksheet. Mark the letter of the best answer to each question. Follow your teacher's instructions for submitting the document.
The abstract class provides a common definition of a base class that can be shared by multiple derived classes. The abstract class often provides incomplete implementation. To instantiate an abstract class you must inherit from it and complete the implementation.
Directions: Describe in your own words: What are the similarities and differences between abstract classes and interfaces? Please follow your instructor's directions to participate in the discussion.
Directions: Compare and contrast the similarities and differences between Java interfaces and abstract classes. Your compare/contrast should include at least 5 similarities and 5 differences. You could create a comparison table or a Venn diagram. The document should be visually appealing with:
Students may complete this assignment on paper or on the computer. Follow your teacher's instructions for submitting your assignment.
Directions: Download the Interface Worksheet. Mark the letter of the best answer to each question. Follow your teacher's instructions for submitting the document.
Directions: Download the Abstract Classes Worksheet. Select the letter of the best answer to each question. Follow your teacher's instructions for submitting the document.
Directions: Read this short lesson explaining inheritance from Columbus State: Inheritance. The code is especially helpful to review. Then download the Exploring Inheritance (Dogs) lab document. File Dog.java contains a declaration for a Dog class. Save this file to your directory and study it--notice what instance variables and methods are provided. Files Labrador.java and Yorkshire.java contain declarations for classes that extend Dog. Save and study these files as well.
File DogTest.java contains a simple driver program that creates a dog and makes it speak. Study DogTest.java, save it to your directory, and compile and run it to see what it does.
Directions: Download the Dealer Class Abstract Lab.
Extend class Person to make a Dealer class. You must provide 2 constructors for class Dealer. You must implement the talk method so that Dealer will say "I wish to Stay!".
Your response must be handwritten.
Polymorphism is the ability of derived classes to share common functionality with base class but still define their own unique behavior.
Polymorphism allows the objects of a derived class to be treated at runtime as objects of the base class. When a method is invoked at runtime, its exact type is identified, and the appropriate method is invoked from the derived class.
To learn more about Polymorphism, visit http://interactivepython.org/runestone/static/JavaReview/OOBasics/ooPoly.html.
Directions: Draw a class hierarchy for types of teachers at a high school. Show what characteristics would be represented in the various classes of the hierarchy. Explain how polymorphism could play a role in assigning courses to each teacher. Upload a picture of your hierarchy and include your explanations in the itsLearning textbox.
Directions: Answer the questions in the Polymorphism Questions worksheet in itsLearning.
Directions: Design and implement a set of classes that define the employees of a hospital: doctor, nurse, administrator, surgeon, receptionist, janitor, and so on. Include methods in each class that are named according to the services provided by that person and that print an appropriate message. Create a main driver class to instantiate several of the classes. Copy and paste your code form BlueJ to the itsLearning textbox and submit a screenshot from the BlueJ terminal window.
The Super Reference: presentation
Designing for Inheritance: presentation
Abstract Classes: presentation