OOP IN JAVA ( METHOD OVERLOADING)

 Method Overloading 


Method overloading is a feature of Java in which a class has more than one method of the same name and their parameters are different.”

In other words, we can say that Method overloading is a concept of Java in which we can create multiple methods of the same name in the same class, and all methods work in different ways. When more than one method of the same name is created in a Class, this type of method is called the "Overloaded Method".

And also, you have to perform the addition of give numbers but there can be so many numbers of arguments (say either 2 or 3 arguments for simplicity)
 In order to accomplish the task, you can create methods void h1(int, int) and                               void h1(int, int, int) for two and three parameters respectively. However, other programmers, as well as you in the future may get confused as the behavior of both methods are the same but they differ by paras.
The better way to accomplish this task is by overloading methods. And, depending upon the argument passed, one of the overloaded methods is called. This helps to increase the readability of the program. 


                                                void a1(int c) {

}

void a1(int f, int g) {

}

void a1(string a, int b) {

}

void a1() {

}

 

 

a1 (4,5)

a1 ()

a1 (“234”,12)

a1 (45)

                                              

(This diagram above shows how method overloading is done and the same color are run together.)


Access Modifiers


The security to access classes methods and variables is called modifiers.

As the name suggests access modifiers in Java helps to restrict the scope of a class, variable, method, There are four types of access modifiers available in java:

They are :

Modifier  

Description

Public 

declarations are visible everywhere.

Protected 

declarations are visible within the package or all subclasses.

Default 

declarations are visible only within the package (private Package) 

Private 

declarations are visible within the class only
















Comments

Popular posts from this blog

DEMYSTIFYING THE POWER OF x86 ARCHITECTURE

A GUID TO BEACOMING A SOFTWARE ENGINEER

JAVA LAMBDA EXPRESSION