-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNotes1014.txt
More file actions
29 lines (20 loc) · 767 Bytes
/
Notes1014.txt
File metadata and controls
29 lines (20 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Aim: How do we extend classes?
extends
Java keyword used to create a subclass
example: public class Mage extends Character
You cannot extend more than one class
There is no limit to the levels of subclasses that
can be made.
Subclasses inherit all instance variables and methods
except for constructors (more on that later).
private instance variables in a superclass are
inherited by subclasses, but cannot be accessed by
the subclass.
The PROTECTED keyword makes instance variables
accessible by a class and its subclasses
Method inheritance
Subclasses can create their own version of inherited
methods, this is known as overriding a method (think
about toString)
You can call the superclass's version of a method with
the SUPER keyword.