what is overloading in java?

Answer Posted / srujana

To define one or more methods within the same class that
share the same name, as long as thier parameters
declarations are diffrent.These methods are called
overloaded and its process is called Methodoverloading.
For example,
class Demo
{
void test()
{
System.out.println("No parameters");
}
void test(int a)
{
System.out.println("a is:"+a);
}
void test(int a, int b)
{
System.out.println("a is:"+a "," +b);
}
}
class Demo1
{
public static void main(String args[])
{
Demo1 d=new Demo();
d.test();
d.test(5);
d.test(2,3);
}
}

Is This Answer Correct ?    27 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we have static methods in an interface?

801


What is meant by string is immutable?

741


what is inner class in java?

861


Are floats faster than doubles?

783


What is style and indentation?

773


In case of inheritance what is the execution order of constructor and destructor?

876


Can we have try without catch block?

860


what is the messsage u r going to get from an objectoriented programing?

1897


What is static and final keyword in java?

780


How objects of a class are created if no constructor is defined in the class?

811


What is garbage collector?

823


What does @param args mean in java?

820


How many types of voids are there?

761


Why does java not support pointers?

781


when should you use stringbuilder class in a program?

747