JAVA Methods Overload

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Unit 1: Programming

Unit code: D/615/1618


Unit level: 4

Content Prepared by:

School of Computing and Informatics 1


2

Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed


FUNCTIONS
OVERLOADING
With method overloading,
multiple methods can have
the same name with different
parameters

Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed 3


Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed 4
There are 3 ways to overload the method in
java
WAYS TO ▪ By changing number of parameters
▪ By changing the data type of the
OVERLOAD A parameters
METHOD ▪ By changing the order of the parameters (if
different datatypes are involved)

Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed 5


▪ Overloading is related
to polymorphism
(later in the course)

Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed 6


▪ Overloading Improves
readability

Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed 7


▪ Instead of defining two methods that
should do the same thing, it is better
to overload one.

Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed 8


This is how method
overload looks in
the IDE

Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed 9


10

Prepared by: Ms. Dania Alsaid, Ms. Hana Alrasheed

You might also like