Java Concepts | Techbirds

RULES MUST BE FOLLOWED WHILE VARIOUS OVERLOADED METHODS ARE GIVEN.

PRIORITY: AUTOWIDENING > AUTOBOXING > AUTOUPCASTING > VAR-ARGS…

(Above Priority sequence must be followed while calling when multiple overloaded methods occurs)

class A { public static void main(String …arg)

{

show(20); /*…..at this point of instant 1st show method is called . step 1: if we comment 1st show method,then AUTOWIDENING(int>long)occurs and 2nd show method is called. step 2: if we comment 1st and 2nd show methods,then AUTOBOXING(int>Integer)occurs and 3rd show method is called. step 3: if we comment 1st,2nd and 3rd show methods,then AUTOBOXING+AUTOUPCASTING(int>Integer>Number)occurs and 4th show method is called. step 4 : if we comment (1st,2nd,3rd,4th) show methods ,then VARARGS(5th)show method is called. ….. */ } //1st show method static void show(int a) { System.out.println(“int”); } //2nd show method static void show(long a) { System.out.println(“long”); } //3rd show method static void show(Integer a) { System.out.println(“Integer”); } //4th show method static void show(Number a) { System.out.println(“Number”); } //5th show method static void show(int …a) { System.out.println(“int…”); }

}

443 total views, 2 views today

Share this Onfacebook-1701800twitter-8629016linkedin-2373100google-2421675