+ 2

There is something wrong with this example. I tried many times both on note++,eclipse and sololearn console but not working.

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''); } } //OUTPUT = B

5th Oct 2016, 8:34 PM
Yigit
Yigit - avatar
3 Réponses
0
every thing seem OK
5th Oct 2016, 9:05 PM
Ashraf Ali Mohammed Naji Sinan
Ashraf Ali Mohammed Naji Sinan - avatar
0
When i tried same codes like above i got below error message; ..\Playground\:3: error: <identifier> expected public void do() { ^ I tried again but this time i changed both method names as Do() like below it worked; 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"); } }
5th Oct 2016, 9:57 PM
Yigit
Yigit - avatar
0
In JAVA , There are some keywords and do keyword is one of them , So in java you can't give the keywords as the name of class ,methods and interfaces. So you have to change your methods name.
19th Oct 2016, 3:10 AM
Dhruv Rajkotia