+ 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?
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.
+ 2
B answer..
+ 1
C
+ 1
Definitely it will print c because argument is 12 given which is int and belongs to c.
0
Answer is "c"
0
c
0
The correct answer is: C
0
c
0
c
0
B
0
c
0
c
0
c