Types of Method(Polymorphism):

There are two types of Method in Java:
1)Method Overloading
2)Method Overriding

What is the need of Method Overloading and Method Overriding

class student{
	int id=1000;
	String name="bhanu";

   //Declare first method with showid name	
    void showid(){
		System.out.println(id);
	}
  //Declare second method with showname name	  
    void showname(){
		System.out.println(name);
	}
			 
	public static void main(String args[]){
		student s=new student();
		
		//call of first method---showid
	    s.showid();
		//call of second method--showname
		s.showname();
	}
}
          

OUTPUT:
1000
bhanu
          

Conclude:

In above program,we identify there are two methods with different name.
Let suppose if there are 100 method in one project.
Then we have to create 100 unique method name,which become problem for managing project

Above problem is solved by using :

Method Overlaoding
Method Overriding

Method Overlaoding:

Method have same name in class but they are very in following parameters:
1) Number of Parameters
2) Types of Data types

CASE I--Different number of parameters:

Syntax

Syntax:
void show();
void show(int x);
void show(int x, int y, int z);
Or
void show(string name);
void show(String name1,String name2);	
void show(String name1,String name2,String name3)

          

Example

class student{
    	
	//declare first method with show name 
	//it have one arguments
	void show(int x){
	  System.out.println(id);
    }
	
    //declare first method with show name 
	//it have two arguments	
	void show(int x,int y){
	  System.out.println(x+" "+y);
    }
	
    //declare first method with show name 
	//it have three arguments	
	void show(String name1,String name2,String name3){
      System.out.println(name1+" "+name2+" "+name3);
	}

	public static void main(String args[]){
	    student s=new student();
		s.show(11);
		s.show(212,345);
		s.show("max","sam","John");
	}
}
          

OUTPUT:
11
212 345
max sam John
          

Case 2: different type of data types

Syntax



void show(int  x ,String name );
void show(int  x, int y, String s);
Or
void show(String name ,int  x);
void show(String name1,String name2,int x)

          

Example


class student{
    //declare first method with show---> name 
	//it have two arguments
    void show(int x,int y){
	  System.out.println(x+" "+y);
    }
	
    //declare second method with showname--> name 
	//it have one arguments	
    void showname(String name1,String name2){
	   System.out.println(name1+" "+name2);
	}
			 
	public static void main(String args[]){
	    student s=new student();
		s.show(123,456);
		s.show("max","sam");
	}
}
          

OUTPUT:
123 456
max sam
          

Address

Plot number-56/1
Near Gurudwara
LandMark :
Opposite A.N.D college
Govindpuri Metro station
New Delhi
Mobile number:
8826034620