- Computers & Software»
- Computer Science & Programming»
- Programming Languages
Java Programming with Eclipse-The Best Beginners Tutorial:Overloading And Overriding In Java
In my last java eclipse programming tutorial I have told you that how to write and run any programme in eclipse.Function overloading and overriding in java are very important topic in java that's why they are asked in number of interview questions.Therefore, In this tutorial I am talking about function overloading and overriding in java.
Although there are other tutorial subjects also like if else, while, do while. These topics are very well known to you and there are number tutorial on these topics. So I am coming directly toward overloading and overloading in java.Be rest assured each tutorial is seperate tutorial.Therefore you can read any tutorial.
method over loading in java
Overloading is the term used for java function which have same name but different signature .The return type can be different but it doesn’t affect overloading. Mainly the focus is on signature or parameter. If you know the basics of java, then you must have heard of polymorphism.
There are three main basic concepts in java that is encapsulation, inheritance and polymorphism. In java polymorphism is achieved through overloading and overriding. It can be better understood by this example.
Copy the above program as such in eclipse IDE. If you will see, we have defined three functions in the class with different signature. Now when we call 1st function. Java compiler matches the number of argument in calling function and called function .Here for example, calling function is example.sum(24) and called function is sum function with one argument written in class.
When second function is called java matches the function with 2 integer argument with sum function. Similarly in last function, argument is of type double. As we can see there is only one function available of this type therefore that will be called.
Method overrding in java
Overriding in java is more than one function with same name and same signature(argument) .This can be better understood by the example:
Buy Wonder Java Book For Begginners
Here function named call in Multiple subclass is overrding the function declared in superclass. According to type of object(in this case multi) we are referring through new operator,that type of function will be called from the class.
Here we are referring multiple object through new operator. If we had created an object of MultipleRide then that class function would have called.
Other Java Tutorial You Might Like
- Java Programming with Eclipse-The Best Beginners Tutorial:Part 1
Java with eclipse is the deadly combination.This beginners tutorial will take you through the every detail of java ecplise programming...