- Use inheritance in creating classes
- If no default constructor is present in the superclass, explain why a constructor of a subclass should make an explicit call to a constructor of the superclass
- Explain what is meant by "overriding a method"
- Make use of
super
reference to call a parent method from within a method that overrides it - Implement source code that meets the design specified in a UML class diagram
Note taking requirement
Don't forget to submit your notes in Canvas prior to classtime.
Reading
- Study sections 13.1 and 13.3-13.5 of the textbook
- Read section 13.2 of the textbook
Shape Class Introduction [7:05]
- What is a parent class?
- Give an example of a parent class?
- What is a child class?
- Give an example of a child class?
- What are the two key reasons for using inheritance?
- Watch the following video [link]
Shape Class Code [9:39]
- Compare UML diagram to source code.
- Which methods of the actuaully change attributes of the
Shape
class? - What package is the
Color
class in? - What is the
Object
class? - What is the parent class of
Shape
?
- Watch the following video [link]
Overriding Methods [3:19]
- When do we need to call
toString()
when inside aSystem.out.println()
call? - What is different about implementing
toString()
than other methods in theShape
class? - How do you set a breakpoint?
- How do you run the debugger in IntelliJ?
- Watch the following video [link]
Child Class Square [6:42]
- What keyword is used to indicate inheriting from a different class?
- How do you access parent methods in the child class?
- What additional instance variables were added to the
Square
class? - How does the constructor of a subclass interact with the constructor(s) of the super class?
- Which method(s) from the
Shape
class were overridden in theSquare
class? - When is the default constructor not available?
- What keyword is used to call a different constructor from a constructor in the same class?
- Watch the following video [link]
Calling Parent's Constructor [10:45]
- What keyword is used to call a constructor from the parent class?
- Note that the constructor from the superclass is executed prior to the subclass' constructor.
- What attributes from the
Shape
class are available inSquare
? - If the parent's constructor is not called explicitly, what constuctor gets alled implicitly?
- Watch the following video [link]
Calling Parent Methods [7:19]
- What keyword do we use the expiclitly can the parent's implementation of a method?
- What are some examples of class hierarchies in the Java standard library?
- What does
@Override
do?
- Watch the following video [link]