+ 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
3 ответов
0
every thing seem OK
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");
}
}
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.