Answer Posted / vikneswarank
method signature means defind the method in diff signature
diff no arguments
diff datatype if arguments
diff sequence of arguments
for example
public class PolyOverload1
{
public int iEmpNo;
protected double dbSalary;
private boolean boolPermanent;
String strEmpName;
public PolyOverload1()
{
System.out.println("PolyOverload constructor");
iEmpNo = 1001;
strEmpName = "Base Employee";
dbSalary = 20000.500;
}
public void getEmpDetails()
{
// to print the employee details
System.out.println("Emp no : " + iEmpNo);
System.out.println("Emp name : " + strEmpName);
}
//no of arguments difference
public void getEmpDetails(int eno)
{
//to print the employee details
System.out.println("Emp no [getEmpDetails(int eno)]
: " + eno);
System.out.println("Emp name [getEmpDetails(int
eno)] : " + strEmpName);
}
//different type of data type
//note : return type can be different for overloading
public int getEmpDetails(String ename)
{
// to print the employee details
System.out.println("Emp no [getEmpDetails(String
ename)] : " + iEmpNo);
System.out.println("Emp name [getEmpDetails(String
ename)] : " + ename);
return iEmpNo;
}
//no of arguments difference
public void getEmpDetails(int eno, String ename)
{
// to print the employee details
System.out.println("Emp no [getEmpDetails(int eno,
String ename)] : " + eno);
System.out.println("Emp name [getEmpDetails(int eno,
String ename)] : " + ename);
}
//different seguence type of data type
public void getEmpDetails(String ename, int eno)
{
// to print the employee details
System.out.println("Emp no [getEmpDetails(String
ename, String eno)] : " + eno);
System.out.println("Emp name [getEmpDetails(String
ename, String eno)] : " + ename);
}
public static void main (String arg[])
{
//Object creation
PolyOverload1 polyObj = new PolyOverload1();
//static binding or early binding...during compile
time JVM will find that the method's reference to call
polyObj.getEmpDetails();
polyObj.getEmpDetails(1002);
polyObj.getEmpDetails("Test Employee1");
polyObj.getEmpDetails(1003, "Test Employee2");
polyObj.getEmpDetails("Test Employee3", 1004);
}
}
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
What all methods are used to prevent thread execution ?
What does it mean that strings are immutable?
What is return code?
Is it possible to specify multiple jndi names when deploying an ejb?
How to display all the prime numbers between 1 and n (n is the number, get the input from user)
What are java methods?
what is anonymous class in java?
What are the differences between getting and load method?
What is lazy initialization in java?
In how many ways we can do synchronization in java?
Where is stringbuffer stored?
How is Object Oriented Programming different from Procedure Oriented Programming?
A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.
Explain the term virtual machine?
What is mnemonic in assembly language?