-
-
Lecture1.1
-
Lecture1.2
-
Lecture1.3
-
Lecture1.4
-
Lecture1.5
-
Lecture1.6
-
Lecture1.7
-
Lecture1.8
-
Lecture1.9
-
Lecture1.10
-
Lecture1.11
-
Lecture1.12
-
Lecture1.13
-
Lecture1.14
-
Overloading vs Overriding
Java permits a class to replace (or override) a method that it has inherited. A subclass can define a method with the SAME signature as a superclass method.
Overloading
Two methods have the same name but DIFFERENT signatures — the parameter types and/or the number of parameters are different.
[php]
public StringBuilder append (int a);
public StringBuilder append (String s);
public StringBuilder append (int a, int b);
[/php]
Overriding
A method in the subclass has the SAME signature as a method in the superclass.
Calling An Overridden Method Within a subclass definition, you can call the superclass method with the “super” reference.
[php]
[/php]