method overloading

method overloading

View Answers

June 4, 2009 at 9:44 AM

class overloadingDemo
{
public void sumload(int a,int b) //ex:This will be called by sumload(2,4)
{
int n=a+b;
System.out.println("Sum="+n);
}
public void sumload(int a,int b,int c) //ex: calling sumload(10,20,30)
{
int n=a+b+c;
System.out.println("Sum:"+n);

}
//Remember: both methods have same name sumdemo() but different arguements



}

June 4, 2009 at 12:57 PM

Hi Friend,

In Java, the methods having the same name within the same class with different parameters are said to be overloaded and this process is referred to as Method Overloading. In the given example, we have defined the method add() twice with different parameters showing Method Overlaoding.

class MethodOverloading{

public void add(int a, int b) {
int sum=a+b;
System.out.println("Sum of two numbers = "+sum);
}
void add(int a,int b,int c) {
int sum=a+b+c;
System.out.println("Sum of three numbers = "+sum);
}
public static void main(String args[]) {
MethodOverloading overloading = new MethodOverloading();
double result;
overloading.add(5,6);
overloading.add(5,6,7);
}
}

Thanks









Related Tutorials/Questions & Answers:
method overloading
method overloading   public void test(int a); pulic void test(long a);which sutiation x.long is called
Method Overloading
Method Overloading  In java can method be overloaded in different class
Advertisements
Method Overloading
Method Overloading  In java can method be overloaded in different class
method overloading
method overloading  public void test(int a){} public void test(long a){} i will call some x.test(125) which method is called pls tell me
method overloading
method overloading  public void test(int a) public void test(long a) public void test(object a) i will call some x.test(1258448); which method is called if it is called first one why it not call the third one
method overloading
method overloading  what is output of this program & why class Test { public void display(String msg) { system.out.println(msg); } public void display(Object msg) { system.out.println(msg
method overloading in c program
method overloading in c program  how is method overloading in C program is different from C++ program
JAv method overloading
JAv method overloading  What restrictions are placed on method overloading
What restrictions are placed on method overloading?
What restrictions are placed on method overloading?   Hi, What restrictions are placed on method overloading? thanks
Method overloading in java program
Method overloading in java program  How can we use method overloading in java program?   Method overloading:?In method overloading methods have same name but different type of parameters. Here is an example of method
method overloading - Java Beginners
is referred to as Method Overloading. In the given example, we have defined...method overloading   Write a program to demonstrate the method overloading for sum ( ) function.  class overloadingDemo { public void
Main method overloading
Main method overloading  Can we overload main()method
What is use of method overloading and overriding?
What is use of method overloading and overriding?  Method overriding...() method of Object class, we can use it with different classes. Overloading... = window.adsbygoogle || []).push({}); Java Method Overloading Java Method
Method Overloading Example In Java
Method Overloading Example In Java In this section we will read about overloading in Java. Method overloading in Java is achieved due to the Java supports... with the same name. The concept of method overloading allows the Java programmer
Polymorphism : Method Overloading
In this tutorial you will learn one of polymorphism concept that is method overloading with example in Java 7
Java Method Overloading - Java Beginners
Java Method Overloading  can method be overloaded in subclass or not?  Hi Friend, Yes A subclass can overload the methods.For Example...: http://www.roseindia.net/java/master-java/method_overloading.shtml Thanks
Java method overloading
Java method overloading       Example below demonstrates method overloading in java. In java  method overloading means creating more than a single method with same name
calculate volume of cube, cylinder and rectangular box using method overloading in java
calculate volume of cube, cylinder and rectangular box using method overloading... method overloading in java   calculate volume of cube, cylinder and rectangular box using method overloading in java
Overloading
Overloading  program in method overloading it compile successfully and gives error in run time?   Hi Friend, Post your code. For more information, you can visit the following link: Method Overloading Example Thanks
Method Overloading
Method Overloading       As we know that a method have its own signature which is known by method's name and the parameter types. Java has a powerful feature which is known as method
Overloading
Overloading  Overloading in JAVA
Method Overloading in java
Method Overloading in java      ...: 1. Method Overloading 2. Method Overriding   Here we will discuss only the concept of Method Overloading: -- In a class, the concept of method
overloading and overriding
overloading and overriding  hello, What is the difference between overloading and overriding?   hiiADS_TO_REPLACE_1 Overloading: Overloading is nothing but passing the different parameters to the method. Here method
Constructor overloading in java
Constructor overloading in java In this section we will discuss about constructor overloading in java. Constructor overloading is not much different from method overloading, in method overloading you have multiple method with same
Overloading in java
The overloading in seen with the constructor and the methods of the class The following link have all the details Constructor overloading in Java Method overloading in Java
write a program to calculate volume of a cube, cylinder, rectangular box using method overloading
write a program to calculate volume of a cube  write a program to calculate volume of a cube, cylinder, rectangular box using method overloading  
question related to overloading
question related to overloading  what is difference between function overloading & method overloading
question related to overloading
question related to overloading  what is difference between function overloading & method overloading
Method overriding or overloading
examples for overloading and overriding
examples for overloading and overriding  examples for overloading and overriding
overloading - Java Server Faces Questions
overloading  define overloading   Hi Friend, Overloading is the ability to define more than one method with the same name in a class. Example: class Overloading { void test() { System.out.println("Hello
overloading and overriding in c
overloading and overriding in c  can anyone explain the concept of overloading and overriding in reference to c programming...through an example if possible
ModuleNotFoundError: No module named 'overloading'
ModuleNotFoundError: No module named 'overloading'  Hi, My Python... 'overloading' How to remove the ModuleNotFoundError: No module named 'overloading' error? Thanks   Hi, In your python environment
c++ operator overloading
c++ operator overloading  What is operator overloading? and what is mean by overloading?? Can anyone please explain the concept in regards to C
Overloading constructor in flex
Overloading constructor in flex  Hi...... What is overloading a constructor? How do you overload constructors in flex? please tell me about... not support overloading constructors.ADS_TO_REPLACE_2 Thanks
What is Overloading of procedures ?
What is Overloading of procedures ?  What is Overloading of procedures ?   The Same procedure name is repeated with parameters of different... of parameters is called overloading of procedures. e.g. DBMSOUTPUT putline
OVERLOADING AND OVERRIDING - Java Interview Questions
OVERLOADING AND OVERRIDING  When Use OverLoading?When Use OverRiding Can U Explian Brifely
function overloading in c
function overloading in c  are int func1(int x, int y) and void func1(int x, int y) overloaded? can the functions with same name same arguments but different return types be overloaded
method
method   how and where, we can define methods ? can u explain me with full programme and using comments
method
method  can you tell me how to write an abstract method called ucapan() for B2 class class A2{ void hello(){ system.out.println("hello from A2"); }} class B2 extends A2{ void hello(){ system.out.println("hello from B2
Why does Java not support operator overloading?
Why does Java not support operator overloading?  Hi, Why does Java not support operator overloading? thanks
What is Constructor Overloading in Java?
What is Constructor Overloading in Java with examples... will learn about the construction overloading in Java and understand this concept... in the constructor. Whenever we assign the name of the method same as  class name
What is Constructor Overloading in Java?
What is Constructor Overloading in Java with examples... will learn about the construction overloading in Java and understand this concept... of the method same as  class name. Remember this method should not have any return
Method
and the other one is the class method.     Method Overloading... is known as method overloading. With the help of this feature we can define two methods... Method      
Java Constructor Overloading Example
Java Constructor Overloading Example In this section we will read about the constructor overloading in Java. We will see how the constructor overloading... programming is called constructor overloading. Constructors with different
Constructor Overloading in Java
In this section we have discussed about Constructor Overloading in Java... and then overloads them. Following example of Constructor Overloading will help you understand...: Constructor Overloading in Java Java Constructor
Tell me where we are using overloading and overriding in realtime project?
Tell me where we are using overloading and overriding in realtime project?  Hi,Tell me where we are using overloading and overriding in realtime project? please give me answer
SCJP Module-4 Question-5
) { ...} } Is the method overloading correctly used(in the above code) ? Choose correct option : 1.Correct , method overloading is used 2.Correct ,method overriding...;count as overloading
method inside the method??
method inside the method??  can't we declare a method inside a method in java?? for eg: public class One { public static void main(String[] args) { One obj=new One(); One.add(); private static void add
get method
get method   how to use get method: secure method is post method and most of use post method why use a get method

Ads