- 1

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); } }

29th May 2020, 12:23 PM
Emanuela Telescu
Emanuela Telescu - avatar
4 Answers
0
This is a bad practice. Why don’t you use different function names instead? Unless you need to create a template function for multiple type of objects, you can use generics. Here’s an article about it: https://www.geeksforgeeks.org/generics-in-java/
29th May 2020, 2:06 PM
Bobby Fischer
Bobby Fischer - avatar
+ 3
Output is - c Because the third function is running in this class which has integer argument
29th May 2020, 12:24 PM
Aditya Dangayach
Aditya Dangayach - avatar
+ 2
oh yes, you are right...thank you
29th May 2020, 12:26 PM
Emanuela Telescu
Emanuela Telescu - avatar
0
C
18th Aug 2024, 5:52 AM
Anu Kushwaha
Anu Kushwaha - avatar