Overloaded methods:

- Overloaded methods MUST change the argument list
- Overloaded methods CAN change the return type
- Overloaded methods CAN change the access modifier
- Overloaded methods CAN declare new or broader checked exceptions
- A method can be overloaded in the same class or in a subclass

Overriding Methods:

- The overriding method cannot have a more restrictive access modifier than the method being overridden (Ex: You can’t override a method marked public and make it protected).
- You cannot override a method marked final.
- You cannot override a method marked static.

....

Arguments

Return type


Exceptions



Access Modifier


Invocation




Constructors

Polymorphism

Inheritance

Class

Overloading

Must change.

Can change.


Can change.



Can change.


Reference type determines which overloaded version is selected. Happens at compile time.

Can be overloaded.

Not applies to overloading.

Not applies to overloading.

Method overloaded in same class or subclass.

Overriding

Must not change.

Can’t change except for covariant returns.

Can reduce or eliminate. Must not throw new or broader checked exceptions.

Must not make more restrictive (can be less restrictive).

Object type determines which method is selected. Happens at runtime.


Cannot be overridden.

Applies to overriding.

Applies to overriding.

Method overriding occurs in subclass.
 





Leave a Reply.