Grokking Java Interview Questions
0% completed
Overriding and Overloading
static String add(long quantity) { return "add(long)"; } static String add(Integer quantity) { return "add(Integer)"; } static String add(int... quantities) { return "add(int...)"; } System.out.println(add(50));
Three methods share the name add, and each of them can accept the int value 50. The program compiles and prints add(long), although Integer and int... look like closer matches.
The four questions that follow explain this choice and the related rules
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%