0
What is wrong with the code below? Can anybody say why can't i call a non-static method from a static method?
class MyClass { void sayHello(String name) { System.out.println("Hello " + name); } public static void main(String[ ] args) { sayHello("David"); sayHello("Amy"); } }
7 ответов
+ 7
a non-static method of a class must have an instance of the class to process.
MyClass obj = new MyClass();
obj.sayHello("David");
+ 5
Rugved Modak Nathan I don't mind it at all.
+ 3
Just so you know Nathan , John Wells is much elder and a lot more experienced than you, to call him mate.
+ 3
Ok. I think it's just your modesty.
+ 3
You could simply see his display pic and gold mod status. Anyways, if he doesn't have a problem, I won't mind too.
+ 2
Thanks mate!
+ 1
I was just focusing on the answer so i didn't see his profile 😅