Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Interview-Questions What is use of method overloading and overriding?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


SrinivasM
What is use of method overloading and overriding?
1 Answer(s)      3 years and 9 months ago
Posted in : Java Interview Questions


Method overriding means same method has written in both child and parent classes.overloading means write same method with different signatures.But I want to know what is the use of these concepts.how to use this type of polymorphism in real time? thanks in advance


Advertisement
View Answers

April 6, 2011 at 3:46 PM


Overriding is useful when you want to change the functionality of some method based on a class. For example, by overriding the toString() method of Object class, we can use it with different classes.

Overloading is useful to add flexibility to a method. In general, if you want to create a method that adds two numbers then it only take either integer, double, or float but by overloading, you can add values of all data types.

Java Method Overloading

Java Method Overriding



Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com