Output in Java, class, methods | Sololearn: Learn to code for FREE!

+2

Output in Java, class, methods

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ąk

10 Answers

New Answer

+6

in 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.

+1

0

Answer is "c"

0

0

The correct answer is: C

0

0

0

B answer..

0