Skip to the content
onlineexamguide
  • Home
  • Courses
  • Engg. Interview
    • Placement Papers
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
  • Online Exam
    • NTA UGC NET Exam
    • SSC Examination quiz
    • TET Examination Quiz
    • Banking Exam
    • Aptitude Tests
    • Computer Knowledge Tests
    • Logical Reasoning Tests
    • English Language Tests
    • Staff Nurse Exams
    • General Knowledge Tests
    • Networking Tests
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
  • User Login
  • Home
  • Courses
  • Engg. Interview
    • Placement Papers
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
  • Online Exam
    • NTA UGC NET Exam
    • SSC Examination quiz
    • TET Examination Quiz
    • Banking Exam
    • Aptitude Tests
    • Computer Knowledge Tests
    • Logical Reasoning Tests
    • English Language Tests
    • Staff Nurse Exams
    • General Knowledge Tests
    • Networking Tests
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
  • User Login

Method Overloading in Java Tutorial and Interview MCQ

Method Overloading in Java

Study and learn Interview MCQ Questions and Answers on Java Method Overloading. Attend job interviews easily with these Multiple Choice Questions

what is method overloading in java

Java Method Overloading is nothing but the ability to write more than one Method with the same name in a Class with varying Return-Types or Parameters. In other words, you should maintain unique method signatures for all methods with the same name to successfully Overload. Let us know more about Method Overloading in this Java Tutorial.

You can read more about Constructor Overloading in Java for better understanding.

Method Overloading in Java

Java methods contain reusable pieces of code that can be called any number of times. and Java methods can receive arguments and return values. Parameters or Return values can be primitives or objects.

We simply maintain unique method signatures while maintaining the same method name to Overload a Java Method.

Rules to Overload a method:

  1. If Parameter-list is the same, Return-type can be Super-Class or Sub-Class type.
  2. and If the Parameter list is different, the return value can be either the same or different.
  3. If the return-type is same, the Parameter or Argument list should be distinct or different.

Let us check the below example 1.

public class Bank
{
  int amount=0;
  void addAmount(int amt)
  {
    amount = amount + amt;
  }
  void addAmount(String strAmt)
  {
    amount = amount + Integer.parseInt(strAmt);
  }
  int addAmount(double amt)
  {
    amount = amount + (int)amt;
    return amount;
  }

}

In the above example, we have Overloaded a Java method namely “addAmount“. We have used “void” and “int” as return types for all the methods with the same name “addAmount”. and We differentiated the overloaded methods by varying the data-type of the received parameter or argument. We have shown variation by using int, String and double types. The String is an Object-type parameter.

Let us check the below example 2.

class School
{
  int message(String msg) //error overloading
  {
    System.out.println("Message: " + msg);
    return 0; //some value
  }

  void message(String msg) //eror overloading
  {
    System.out.println("Message: " + msg);
  }
}

Above example throws a Java error like “Duplicate method message(String) in type School“. Because the two methods have the same parameter list and different return-types. Return types should have been Subclass and Superclass types to successfully Overload methods.

[WpProQuiz 160]

Write a comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • Atal Bihari Vajpayee | श्री अटल बिहारी वाजपेयी जीवन परिचय
  • सम्राट अशोक का जीवन परिचय (Emperor Ashoka)
  • Prithviraj Chauhan
  • बाल गंगाधर तिलक
  • स्वामी दयानंद सरस्वती
  • UPPSC Mines Inspector Recruitment 2022 Notification Out
  • AIIMS Delhi JR Vacancy 2022 [194 Post] Notification and Apply Online
  • भीमराव अम्बेडकर
  • डॉक्टर राजेंद्र प्रसाद का जीवन परिचय
  • श्रीनिवास रामानुजन का जीवन परिचय
  • Amnesty International day
  • World Economic Forum
  • UPSSSC VDO Syllabus and Exam Pattern 2022
  • RBI Officer Grade B Recruitment 2022
  • UKMSSB Assistant Professor Recruitment 2022 Apply Now 339 Post

onlineexamguide

onlineexamguide.com is the ultimate guide that will keep you updated about almost every Exam & Interviews . We aim to provide our readers with an informative details that have been occurring in Examination . Here at onlineexamguide.com , we focus on delivering our readers with the latest exam Pattern Mock test

We Provide Free online test to practice for Competitive exams , Online Exam, Entrance and Interview. Learn and Practice online test for Free and Prepare for your exam online with us

Quick links

  • About us
  • Privacy Policy
  • Instructor Registration
  • Student Registration
  • Java Programming Tests
  • C programming Tests
  • C++ programming Tests
  • Aptitude Tests

Follow us

Free Online Mock Test

  • UPTET PRIMARY Online Test Series
  • Super TET Mock Test in Hindi 2022
  • CTET Mock Test 2022 Paper 1
  • SSC CHSL Online Mock Test
  • SSC MTS Mock Test 2022
  • SSC CGL Mock Test
  • SSC GD Mock Test
  • ccc online test

Search

Learn and Earn

Register as Instructor - Create and sell online courses and coaching services with the best online platform onlineexamguide.com . Build a course, build a brand, earn money

Contact us

For any queries

Email us on - admin@onlineexamguide.com

We will response fast as much as we can
Copyright © 2022 onlineexamguide.com - All Rights Reserved.
error: Content is protected !!

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.