1 of 15

To do: October 18

Take out your Dinosaur class worksheet.

Be ready to write on whiteboard.

2 of 15

To do: October 18

Take out your Dinosaur class worksheet.

Write responses to following questions on the whiteboard:

1) When a subclass extends a superclass, which members from the superclass does the subclass inherit?

2) When implementing a constructor of a subclass, what must the first line of the implementation include?

3 of 15

To do: October 18

1) When a subclass extends a superclass, which members from the superclass does the subclass inherit?

  • A subclass inherits instance variables and methods from the superclass.
  • If the subclass does not declare a constructor, if the superclass contains a no-argument constructor, then Java will automatically call on the superclass no-argument constructor.

2) When implementing a constructor of a subclass, what must the first line of the implementation include?

4 of 15

Homework

  • Complete Inheritance - Troop and Dinosaur worksheet and submit to Hub
  • Complete Repl.it lab 04-01 gcd

Albert's presentation for runtime of Euclidean algorithm

5 of 15

To do:

Compare your Allosaur class implementation with your partner. Then implement class in Repl.it.

6 of 15

Open Monster class in Repl.it

What do you notice about the Monster class that is different from what we've seen so far? List them on whiteboard.

7 of 15

Example of abstract class: Monster class in Repl.it

8 of 15

What is a Concrete class?

A concrete class is one that can be directly created or instantiated, and then used.

In other words, you can create an object from a concrete class definition.

9 of 15

What is an Abstract class?

An abstract class is one where parts of the class are declared abstract, making the whole class abstract.

Those parts of the class that are abstract are incomplete which means that you cannot directly instantiate or create an object using an abstract class.

10 of 15

Example of abstract class: Monster class

What is an advantage of declaring the Monster class abstract?

11 of 15

Abstract classes

Abstract classes are declared abstract and may include:

  • Instance variables (concrete)
  • Constructors (concrete)
  • Methods - modifiers/accessors (concrete)
    • Defined and implemented within the abstract class
  • Abstract methods
    • Header and purpose defined
    • Not implemented

12 of 15

Abstract class

Now that this class is declared abstract, it is incomplete. Any class that inherits this abstract class is required to complete the implementation of all of the abstract methods.

13 of 15

Summary

When a concrete class definition, one that can be instantiated as an object, reaches a level of complexity where it is too complicated to define within one class…

It’s time to break it down by using some inheritance techniques, one of which is the use of an abstract class.

14 of 15

To do: Add another class that extends Monster

15 of 15

Homework:

  • Replit 04-02 and 04-03
  • goFormative - Abstract classes and Replit 04-01, 04-02, and 04-03