ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Java Programming with Eclipse-The Best Beginners Tutorial:Overloading And Overriding In Java

Updated on May 8, 2014

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.

Method overloading in java
Method overloading in java | Source

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:

Overriding in java
Overriding in java | Source

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.

Function overloading and overriding in Video

Comments

    0 of 8192 characters used
    Post Comment

    • krbalram profile imageAUTHOR

      rahul 

      3 years ago from Bangalore

      thanks rajpoot for this encouraging comment.

    • krbalram profile imageAUTHOR

      rahul 

      3 years ago from Bangalore

      thanking you very much rajpoot for your encouraging comment.It is very heartening that this post helped you for learning this basic concept of java.

    • profile image

      rajpoot 

      3 years ago

      very informative ,,thanks

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://hubpages.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)