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.
Objects Revisited | Writing Classes | Encapsulation & Visibility Modifiers | Methods | Review
Directions: Download the vocabulary sheet. Define each word as it relates to Java and object-orientated programming. Submit your definitions to the assignment in itsLearning.
Directions: Create 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: 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 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: 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. Mark the letter of the best answer to each question. Follow your teacher's instructions for submitting the document.
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.