+ 2
In the code in class B , it is given - object.do("B") . And the result is also printed as "B" . Then what is the purpose of the
class A { public void do() { System.out.println(''A''); } public void do(String str) { System.out.println(str); } } class B { public static void main(String[ ] args) { A object = new A(); object.do(''B''); } }
1 Odpowiedź
+ 5
It compiles the second do() method as this one requires a String as an arguement.
A object=new A(); creates an instance of class A.
object.do("B"); will print B