Professional Documents
Culture Documents
Lecture Notes
Inheritance
1
Inheritance: Definition
inheritance: a parent-child relationship
between classes
number of subclasses a
class can have Class Class Class
Class
The class called Object
}
Composition vs. Inheritance
"is a" relationship
Inheritance
"has a" relationship
Composition, having other objects as members
Example
Employee “is a” BirthDate; //Wrong!
14
final Methods and Classes
Declaring variables final
Indicates they cannot be modified after declaration
Must be initialized when declared
Declaring methods final
Cannot be overridden in a subclass
static and private methods are implicitly final
Declaring classes final
Cannot be a superclass (cannot inherit from it)
All methods in class are implicitly final
15