0
What wrong my code?how to fix this?java lesson29
public class Main { public static void main(String[] args) { Loading loading = new Loading(); loading.LoadingMessage(); } } class Loading { public void static LoadingMessage(){ System.out.println("Loading"); } }
4 Answers
+ 8
The LoadingMessage method is marked as static, but it is defined in a non-static inner class. To fix this, you can either remove the static keyword from the method declaration or move the Loading class outside of the Main class and make it a standalone class.
The method signature is incorrect. You have defined the method as public void static LoadingMessage(), but the correct syntax is public static void LoadingMessage().
https://code.sololearn.com/cJ42iUzTuGQT/?ref=app
+ 4
You are trying to access a static function with a object you need to access it via the class itself.
so instead of doing loading.LoadingMessage();
do
Loading.LoadingMessage();
Also STATIC comes before VOID
as functions follow
[PUBLIC/PROTECTED/PRIVATE] [NULL/STATIC] [DATATYPE] [NAME] ([ARGUEMENTS) { CODE }
+ 2
public static void LoadingMessage(){
+ 2
Thankš