Week 3 - inheritance Flashcards
Describe inheritance in a UML diagram
Parent class (base or super class) such as Person with a child class (subclass) such as Employee. Employee is-a person and arrow points towards parent class
What reserved word establishes an inheritance relationship in Java?
Extends ie the child class extends the parent class:
class Employee extends Person { // class contents }
UMLs consist of
Class name
Attributes
Methods
Multiplicity (cardinality) are
Notations placed near the end of an association. Ie a company class may have ‘1’ to denote there is only 1 company but an employee class may have ‘1..*’ To denote “1 or more”
1 - no more than one
- .1 - zero or one
* - many - .* - zero or many
- .* - one or many
Inheritance allows you to derive a new __________ from an existing one.
Class
What reference is used to invoke the parents constructor?
Super
Describe protected access
Protected data can be accessed by methods of the object class and all its subclasses.
True or fale: private data is inherited?
False. Private data isn’t inherited. Public data is
A super reference is used to invoke a parents constructor. How is a parent method invoked?
super.()
This is known as over riding the parents method (the inherited method can then be changed)
Methods declared as ‘final’ modifier cannot be overridden.
Inheritance allows what…
Inheritance allows you to derive a class fork an existing one (is Employee is-a Person)
Polymorphism is…
… the ability of one object type to be treated as though it was another type
Polymorphism allows methods of the same name to behave in different ways? True or false?
True.
By having the same name but different parameters it allows the method to literally have ‘many forms’
toString() is a _______ class
Object class.
Every time we define a toString method we are overriding the object class method
The toString method in the object class is defined to return a string
Can you create objects in an abstract class?
No.
A concrete class is one in which you can create objects.
A base(parent/ super) class can be declared as Abstract to force implemented to create concrete classes from subclasses(child classes) only.