SlideShare a Scribd company logo
BY: HUMA SAMIN
Method Overloading
Method Overloading
In Java it is possible to define two or more methods
within the same class that share the same name, as
long as their parameter declarations are different.
The methods are called overloaded methods.
The process is called method overloading.
When an overloaded method is invoked, Java uses
the type and/or number of arguments t0 determine
which version of the overloaded method to actually
call.
Example
public Class OverLoadDemo
{
void test( )
{
System.out.println(“No parameters”);
}
void test(int a)
{
System.out.println(“a: ”+a);
}
void test( int a, int b)
{
System.out.println(“a: ”+ a+ “b: ”+ b);
}
double test(double a)
{
System.out.println(“a: ”+ a);
return a*a;
}
}
Example cont..
public class OverLoadDemoDriver
{
public static void main(String args[])
{
OverLoadDemo o=new OverLoadDemo( );
o.test( );
o.test(10);
o.test(10,20);
double d;
d=o.test( 10.7);
}
}
Note: 1. Method overloading doesn’t depend on the return type.
2. Automatic type casting is allowed while calling methods.
Method Overloading
Method overloading implements the concept of
polymorphism in java.
“Poly” means many and “morph” means forms.
Constructor Overloading
Just like methods constructors can be overloaded.
One class can have more than one constructors
defined.
All the rules of constructor overloading are the same
as that of method overloading.
Example
public class Student
{
//data members or instance variables
private int rollNo;
public int semester;
//behavior or methods are kept public
// Overloaded Constructors
public Student( )
{
rollNo=10;
semester=2;
}
public Student(int r)
{
rollNo=r;
semester=2;
}
public Student(int r, int s)
{
rollNo=r;
semester=s;
}
public void displayValues( )
{
System.out.println(rollNo);
System.out.println(semester);
}
}
Example cont..
public class StudentDriver
{
public static void main(String args[ ])
{
Student s, s1,s2;
s=new Student( );
s1=new Student(23);
s2=new Student(45,3);
s.displayValues();
s1.displayValues();
s2.displayValues();
}
}

More Related Content

What's hot

Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
RahulAnanda1
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
tanu_jaswal
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Hitesh Kumar
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
baabtra.com - No. 1 supplier of quality freshers
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In Java
CharthaGaglani
 
this keyword in Java.pptx
this keyword in Java.pptxthis keyword in Java.pptx
this keyword in Java.pptx
ParvizMirzayev2
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
Introduction to package in java
Introduction to package in javaIntroduction to package in java
Introduction to package in java
Prognoz Technologies Pvt. Ltd.
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
Madishetty Prathibha
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
Niloy Saha
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
Sohanur63
 
String in java
String in javaString in java
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Pavith Gunasekara
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 

What's hot (20)

Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In Java
 
this keyword in Java.pptx
this keyword in Java.pptxthis keyword in Java.pptx
this keyword in Java.pptx
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Introduction to package in java
Introduction to package in javaIntroduction to package in java
Introduction to package in java
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
OOP java
OOP javaOOP java
OOP java
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 
String in java
String in javaString in java
String in java
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Interface in java
Interface in javaInterface in java
Interface in java
 

Viewers also liked

Overloading in java
Overloading in javaOverloading in java
Overloading in java
774474
 
Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding  in java  hdmIntroduction to method overloading & method overriding  in java  hdm
Introduction to method overloading & method overriding in java hdm
Harshal Misalkar
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
Vinod Kumar
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
Shivam Singhal
 
Matlab L3 Program Flow
Matlab L3 Program FlowMatlab L3 Program Flow
Matlab L3 Program FlowTUOS-Sam
 
Computer simulations in civil engineering
Computer simulations in civil engineeringComputer simulations in civil engineering
Computer simulations in civil engineeringMohamed Fadl
 
Danelle Williams Resume_Healthcare Administration (2)
Danelle Williams Resume_Healthcare Administration (2)Danelle Williams Resume_Healthcare Administration (2)
Danelle Williams Resume_Healthcare Administration (2)Danelle Williams
 
Constructor Overloading in java
Constructor Overloading in javaConstructor Overloading in java
Constructor Overloading in java
One97 Communications Limited
 
Data representation
 Data representation Data representation
Data representation
Ashraf Miraz
 
Methods and constructors in java
Methods and constructors in javaMethods and constructors in java
Methods and constructors in java
baabtra.com - No. 1 supplier of quality freshers
 
Java constructors
Java constructorsJava constructors
Java constructors
QUONTRASOLUTIONS
 
Application of programming languages in civil engineering
Application of programming languages in civil engineeringApplication of programming languages in civil engineering
Application of programming languages in civil engineering
Muhammad Usama Umer
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method Overloading
Michael Heron
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding
Michael Heron
 
Polymorphism in java, method overloading and method overriding
Polymorphism in java,  method overloading and method overridingPolymorphism in java,  method overloading and method overriding
Polymorphism in java, method overloading and method overriding
JavaTportal
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
Dr Sukhpal Singh Gill
 
Server,System Administration Resume
Server,System Administration ResumeServer,System Administration Resume
Server,System Administration ResumeVijay Lingayat
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 

Viewers also liked (20)

Overloading in java
Overloading in javaOverloading in java
Overloading in java
 
Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding  in java  hdmIntroduction to method overloading & method overriding  in java  hdm
Introduction to method overloading & method overriding in java hdm
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Matlab L3 Program Flow
Matlab L3 Program FlowMatlab L3 Program Flow
Matlab L3 Program Flow
 
Computer simulations in civil engineering
Computer simulations in civil engineeringComputer simulations in civil engineering
Computer simulations in civil engineering
 
Danelle Williams Resume_Healthcare Administration (2)
Danelle Williams Resume_Healthcare Administration (2)Danelle Williams Resume_Healthcare Administration (2)
Danelle Williams Resume_Healthcare Administration (2)
 
Constructor Overloading in java
Constructor Overloading in javaConstructor Overloading in java
Constructor Overloading in java
 
Data representation
 Data representation Data representation
Data representation
 
Methods and constructors in java
Methods and constructors in javaMethods and constructors in java
Methods and constructors in java
 
Java constructors
Java constructorsJava constructors
Java constructors
 
Application of programming languages in civil engineering
Application of programming languages in civil engineeringApplication of programming languages in civil engineering
Application of programming languages in civil engineering
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method Overloading
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding
 
Polymorphism in java, method overloading and method overriding
Polymorphism in java,  method overloading and method overridingPolymorphism in java,  method overloading and method overriding
Polymorphism in java, method overloading and method overriding
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Server,System Administration Resume
Server,System Administration ResumeServer,System Administration Resume
Server,System Administration Resume
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 

Similar to Method overloading

Method overloading
Method overloadingMethod overloading
Method overloading
VaibhavSingh531
 
Polymorphism.pptx
Polymorphism.pptxPolymorphism.pptx
Polymorphism.pptx
RiturajJain8
 
Inheritance
InheritanceInheritance
Inheritance
Mavoori Soshmitha
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptx
thamaraiselvangts441
 
C# Method overloading
C# Method overloadingC# Method overloading
C# Method overloading
Prem Kumar Badri
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywords
manish kumar
 
Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)
Geekster
 
Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_online
nishajj
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
Gousalya Ramachandran
 
BCA Oveloading and Overriding (2).pptx
BCA Oveloading and Overriding (2).pptxBCA Oveloading and Overriding (2).pptx
BCA Oveloading and Overriding (2).pptx
SarthakSrivastava70
 
Working with Methods in Java.pptx
Working with Methods in Java.pptxWorking with Methods in Java.pptx
Working with Methods in Java.pptx
maryansagsgao
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
Java2Blog
 
Java programs
Java programsJava programs
Inheritance Slides
Inheritance SlidesInheritance Slides
Inheritance Slides
Ahsan Raja
 
Inheritance
InheritanceInheritance
Inheritance
Jancirani Selvam
 
Core java oop
Core java oopCore java oop
Core java oop
Parth Shah
 
Introduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxIntroduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptx
Poonam60376
 
‫Chapter3 inheritance
‫Chapter3 inheritance‫Chapter3 inheritance
‫Chapter3 inheritance
Mahmoud Alfarra
 

Similar to Method overloading (20)

Method overloading
Method overloadingMethod overloading
Method overloading
 
Polymorphism.pptx
Polymorphism.pptxPolymorphism.pptx
Polymorphism.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptx
 
C# Method overloading
C# Method overloadingC# Method overloading
C# Method overloading
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywords
 
Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)
 
Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_online
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
3 j unit
3 j unit3 j unit
3 j unit
 
BCA Oveloading and Overriding (2).pptx
BCA Oveloading and Overriding (2).pptxBCA Oveloading and Overriding (2).pptx
BCA Oveloading and Overriding (2).pptx
 
Overloadingmethod
OverloadingmethodOverloadingmethod
Overloadingmethod
 
Working with Methods in Java.pptx
Working with Methods in Java.pptxWorking with Methods in Java.pptx
Working with Methods in Java.pptx
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
 
Java programs
Java programsJava programs
Java programs
 
Inheritance Slides
Inheritance SlidesInheritance Slides
Inheritance Slides
 
Inheritance
InheritanceInheritance
Inheritance
 
Core java oop
Core java oopCore java oop
Core java oop
 
Introduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxIntroduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptx
 
‫Chapter3 inheritance
‫Chapter3 inheritance‫Chapter3 inheritance
‫Chapter3 inheritance
 

Recently uploaded

"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 

Recently uploaded (20)

"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 

Method overloading

  • 1. BY: HUMA SAMIN Method Overloading
  • 2. Method Overloading In Java it is possible to define two or more methods within the same class that share the same name, as long as their parameter declarations are different. The methods are called overloaded methods. The process is called method overloading. When an overloaded method is invoked, Java uses the type and/or number of arguments t0 determine which version of the overloaded method to actually call.
  • 3. Example public Class OverLoadDemo { void test( ) { System.out.println(“No parameters”); } void test(int a) { System.out.println(“a: ”+a); } void test( int a, int b) { System.out.println(“a: ”+ a+ “b: ”+ b); } double test(double a) { System.out.println(“a: ”+ a); return a*a; } }
  • 4. Example cont.. public class OverLoadDemoDriver { public static void main(String args[]) { OverLoadDemo o=new OverLoadDemo( ); o.test( ); o.test(10); o.test(10,20); double d; d=o.test( 10.7); } } Note: 1. Method overloading doesn’t depend on the return type. 2. Automatic type casting is allowed while calling methods.
  • 5. Method Overloading Method overloading implements the concept of polymorphism in java. “Poly” means many and “morph” means forms.
  • 6. Constructor Overloading Just like methods constructors can be overloaded. One class can have more than one constructors defined. All the rules of constructor overloading are the same as that of method overloading.
  • 7. Example public class Student { //data members or instance variables private int rollNo; public int semester; //behavior or methods are kept public // Overloaded Constructors public Student( ) { rollNo=10; semester=2; } public Student(int r) { rollNo=r; semester=2; } public Student(int r, int s) { rollNo=r; semester=s; } public void displayValues( ) { System.out.println(rollNo); System.out.println(semester); } }
  • 8. Example cont.. public class StudentDriver { public static void main(String args[ ]) { Student s, s1,s2; s=new Student( ); s1=new Student(23); s2=new Student(45,3); s.displayValues(); s1.displayValues(); s2.displayValues(); } }