This site javatpoint is very useful for programming languages like JAVA,PYTHON,C,C++, Data Structures etc.Java learning Concept also provides technical materials , which are related to latest technologies. We provides very easy lectures to our viewers from beginning to advance level.We focus logical content instead of theoretical content.

Thursday, 26 October 2017

Difference between method overloading and overriding

Difference between method over loading and over ridding.

Java enables the programmer to define several methods in class with the same name, as long as each method has a unique set of parameters. Define two or more methods with same name in a class is called method overloading. If programmer has to perform only one operation, heaving methods with the same name increase readability of the program. When a overload method is called. 
When we can declare two or method with same name and parameters are also be same, and all properties are same then we have called method overriding. 
Method overloading will be defined in the inheritance. We can declare one method in parent class then we can also declare method with same name in sub class, then sub class override methods of the parent class. 
Example : we can explain the combination between method overloading and overriding in a single program. That can be follow. 

class Demo
{
void m1(int a,int b )
{
System.out.println(a+b);
}
void m1()
{
System.out.println("hello");
}
}
class   Test  extends Demo
{
void m1()
{
System.out.println("good by");
}
public static void main(String rags[])
{
Test  ob=new   Test();
ob.m1(10,20 );
ob.m1();
}
}









o/p: 30
       good by


Adbox