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