Chapter 6. Working with inheritance

 

This chapter covers:

  • [7.1] Describe inheritance and its benefits. The need for inheriting classes. How to implement inheritance using classes.
  • [7.2] Develop code that demonstrates the use of polymorphism; including overriding and object type versus reference type. How to implement polymorphism with classes and interfaces. How to define polymorphic or overridden methods. How to determine the valid types of the variables that can be used to refer to an object. How to determine the differences in the members of an object, which ones are accessible, and when an object is referred to using a variable of an inherited base class or an implemented interface.
  • [7.3] Determine when casting is necessary. The need for casting. How to cast an object to another class or an interface.
  • [7.4] Use super and this to access objects and constructors. How to access variables, methods, and constructors using super and this. What happens if a derived class tries to access variables of a base class when the variables aren't accessible to the derived class.
  • [7.5] Use abstract classes and interfaces. The role of abstract classes and interfaces in implementing polymorphism.
  • [9.5] Write a simple Lambda expression that consumes a Lambda Predicate expression Syntax and usage of lambda expressions. Usage of Predicate class.

6.1. Inheritance with classes

6.1.1. The need to inherit classes

6.1.2. Benefits

6.1.3. A derived class contains within it an object of its base class

6.1.4. Which base class members are inherited by a derived class?

6.1.5. Which base class members aren’t inherited by a derived class?

6.1.6. Derived classes can define additional properties and behaviors

6.1.7. Abstract base class versus concrete base class

6.2. Use interfaces

6.2.1. Need for using interfaces

6.2.2. Defining interfaces

6.2.3. Types of methods in an interface

6.2.4. Implementing a single interface

6.2.5. A class can’t extend multiple classes

6.2.6. A class can implement multiple interfaces

6.2.7. Extending interfaces

6.2.8. Modifying existing methods of an interface

6.2.9. Properties of members of an interface

6.3. Reference variable and object types

6.3.1. Using a variable of the derived class to access its own object

6.3.2. Using a variable of a superclass to access an object of a derived class

6.3.3. Using a variable of an implemented interface to access a derived class object

6.3.4. The need for accessing an object using the variables of its base - class or implemented interfaces

6.4. Casting

6.4.1. How to cast a variable to another type

6.4.2. Need for casting

6.5. Use this and super to access objects and constructors

6.5.1. Object reference: this

6.5.2. Object reference: super

6.6. Polymorphism