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 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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''); } }

25th Jun 2018, 10:46 AM
Tom
Tom - avatar
1 Answer
+ 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
25th Jun 2018, 1:43 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar