What is the output of this code? class A { private void print() { System.out.println(''a''); } private void print(String str) { System.out.println(''b''); } private void print(int x) { System.out.println(''c''); } public static void main(String[ ] args) { A object = new A(); object.print(12); } } Can you also ask for a brief explanation of how it works?
12/7/2019 12:18:07 PM
Kacper Bąk10 Answers
New Answerin java when you have many methods with the same name but with different signatures, it's called method overloading. the method object.print() will be called depending on the passed argument. if you call it without any arguments object.print() it will print a. if you call it with any string object.print("abcde") it will print b. if you call it with an int object.print(1234) it will print c.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message