Font Awesome Icons
Tutorial
Menu
Core Java
AWT
Swing
Servlet
JSP
JDBC
Spring
Hibernate
JAVA TUTORIAL
What is Java
History of Java
Features of Java
C++ vs Java
Hello Java Program
Program Internal
How to set path
JDK, JRE and JVM
Internal Details of JVM
Java Variables
Java Data Types
Unicode System
Operators
Keywords
CONTROL STATEMENTS
Java If-else
Java Switch
Java For Loop
Java While Loop
Java Do While Loop
Java Break
Java Continue
JAVA OBJECT CLASS
Java OOPs Concepts
Naming Convertion
Object and Class
Constructor
static keyword
this keyword
JAVA INHERITANCE
Inheritance(IS-A)
Aggregation(HAS-A)
JAVA POLYMORPHISM
Method Overloading
Method Overriding
super keyword
Instance Initializer block
final keyword
Runtime Polymorphism
Dynamic Binding
instanceof operator
JAVA ABSTRACTION
Abstact class
Interface
Abstract vs Interface
JAVA ENCAPSULATION
Package
Access Modifiers
Encapsulation
JAVA ARRAY
Java Array
Java Programs
JAVA TUTORIAL
What is Java
History of Java
Features of Java
C++ vs Java
Hello Java Program
Program Internal
How to set path
JDK, JRE and JVM
Internal Details of JVM
Java Variables
Java Data Types
Unicode System
Operators
Keywords
CONTROL STATEMENTS
Java If-else
Java Switch
Java For Loop
Java While Loop
Java Do While Loop
Java Break
Java Continue
JAVA OBJECT CLASS
Java OOPs Concepts
Naming Convertion
Object and Class
Constructor
static keyword
this keyword
JAVA INHERITANCE
Inheritance(IS-A)
Aggregation(HAS-A)
JAVA POLYMORPHISM
Method Overloading
Method Overriding
super keyword
Instance Initializer block
final keyword
Runtime Polymorphism
Dynamic Binding
instanceof operator
JAVA ABSTRACTION
Abstact class
Interface
Abstract vs Interface
JAVA ENCAPSULATION
Package
Access Modifiers
Encapsulation
JAVA ARRAY
Java Array
Java Programs
Method Overloading in Java
Overloading allows different methods to have same name, but different signatures where signature can differ by number of input parameters or type of input parameters or both. Method overloading increases the readability of the program.
Ways to overload the method in java
By changing number of arguments
By changing the data type
By changing the number of arguments
public class Sum
{
public void sum(int x, int y)
{
System.out.println(x+y);
}
public void sum(int x, int y, int z)
{
System.out.println(x+y+z);
}
public static void main(String args[])
{
Sum s = new Sum();
s.sum(5, 7);
s.sum(5,7,9);
}
}
By changing the data type of arguments
class Sum2
{
void add(int a, int b)
{
System.out.println(a+b);
}
void add(double a, double b)
{
System.out.println(a+b);
}
}
public class OL
{
public static void main(String[] args)
{
Sum2 a=new Sum2();
a.add(5,8);
a.add(3.5,8.5);
}
}
Hi, Welcome to etechvidya
Home
About Us
Tutorial