AP Computer Science A -- Inheritance

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


Inheritance

Assignment: Object-Orientated Programming Terminology Worksheet

Directions:

Review the following terms:

  1. Object-oriented programming
  2. Inperative (procedural) programming
  3. Functional programming
  4. Object
  5. Class
  6. Encapsulation
  7. Abstraction/Information hiding

After viewing the object-orientated programming terminology, complete the Object-Orientated Programming Terminology Worksheet in itsLearning.

Assignment: UML Diagram

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.

Lab: Exploring Inheritance (Dogs)

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.

dogs

Discussion: Inheritance

Directions: Download the Inheritance Worksheet. Mark the letter of the best answer to each question. Follow your teacher's instructions for submitting the document.

Assignment: Inheritance Worksheet

Directions: Complete the Inheritance Worksheet in itsLearning by slecting the letter of the best answer choice to each question.


Abstract Classes

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.

Discussion: Abstract & Interfaces

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.

Assignment: Abstract Class vs. Interface Compare/Contrast

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.

Assignment: Interface Worksheet

Directions: Download the Interface Worksheet. Mark the letter of the best answer to each question. Follow your teacher's instructions for submitting the document.

Assignment: Abstract Worksheet

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.

blackjack

Assignment: Dealer Class Abstract Lab

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

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.

Assignment: UML Diagram - Teachers

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.

Assignment: Polymorphism Questions

Directions: Answer the questions in the Polymorphism Questions worksheet in itsLearning.

Lab: Hospital Employees

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.


Review

Credits