As return type does not play any role in function overloading,and compiler only check the unique existence of only those part of code which is used at calling time..
Then why not this code contain error
class Temp{
Temp(){
System.out.println("Default Constructor");
}
void Temp(){
S.o.p("HEll");
}
public static void main(String a[]){
new Temp();
}
}
Output=Default constructor…//
I am shocked there is NO COMPILE TIME ERROR as copiler only check only those part of code which is used at calling time ,means compiler need to check only unique existence of Temp() and there is no unique existence of Temp().
Kindly elaborate
Because
void Temp()is a method and you should invoke it on instance. It is allowed to declare method with name of the class but invocation is different. You can call only constructor withnewoperator.You can read more about Constructor in JLS#8.8. Constructor Declarations
Major difference here you should note is constructor do not have return types and definition of overloading includes return types.