Professional Documents
Culture Documents
Programming
Topic:
Method Overloading/Overriding
Made by:
Akash Mittal (19E5007)
Meher Adbol (19E5036)
Sachin Tiwari (19E5050)
TOPIC
❑What is Method?
❑Method Declaration.
❑Types of Method.
❑Method Overloading.
❑Method Overriding
Method in Java and why do we use Method -
User-defined Method-
The method written by the user or programmer is known as a
user-defined method. These methods are modified according to
the requirement.
Let’s we use user defined Method in below program-
public class Addition
{
public static void main(String[] args)
{
int a = 19;
int b = 5;
//method calling
int c = add(a, b); //a and b are actual parameters
System.out.println("The sum of a and b is= " + c);
}
//user defined method
public static int add(int n1, int n2) //n1 and n2 are formal paramete
rs
{
int s;
s=n1+n2;
return s; //returning the sum
}
}
Output:
The sum of a and b is= 24
Method Overloading in Java-
Java is an Object-Oriented programming language, and it follows
basic OOPs concepts. Overloading is one of the important concepts
in Java. Overloading allows different methods having the same name
in a class but with different signatures. Signature includes the
number of parameters, the data type of parameters and the
sequence of parameters passed in the method. f we have to perform
only one operation, having same name of the methods increases the
readability of the program. There are two ways to overload the
method in java.
1. By changing number of arguments.
2. By changing the data type.