+ 3

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?

7th Dec 2019, 12:18 PM
Kacper Bąk
Kacper Bąk - avatar
13 Réponses
+ 3
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.
7th Dec 2019, 12:48 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 2
B answer..
30th Apr 2022, 8:52 AM
MAREESWARAN S
MAREESWARAN S - avatar
+ 1
C
29th Dec 2020, 7:16 AM
NELSON IBEH
NELSON IBEH - avatar
+ 1
Definitely it will print c because argument is 12 given which is int and belongs to c.
16th Oct 2022, 5:57 PM
Mani Raj Adhikari
0
Answer is "c"
10th Jun 2020, 1:45 PM
Unnati singh
Unnati singh - avatar
0
c
16th Aug 2020, 10:34 AM
Kazimova Gulbaxor Xasanovna
Kazimova Gulbaxor Xasanovna - avatar
0
The correct answer is: C
9th Mar 2021, 11:41 PM
Rusz Tamás
Rusz Tamás - avatar
0
c
15th Nov 2021, 6:08 AM
Nabila Muftia Ma'ruf Kartono
Nabila Muftia Ma'ruf Kartono - avatar
0
c
1st Jan 2022, 8:34 AM
M.I.M.Aqueel
M.I.M.Aqueel - avatar
0
B
9th May 2022, 6:40 AM
U.L.F. Feroza
0
c
17th Sep 2022, 9:00 AM
Shivamma
0
c
21st Sep 2022, 1:47 AM
Belyse Mugisha
0
c
17th Nov 2022, 12:58 PM
Guy Martial KEYOU