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"); } }

22nd Dec 2022, 2:40 PM
Fly King
Fly King - avatar
4 Answers
+ 7
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
22nd Dec 2022, 2:47 PM
Sadaam Linux
Sadaam Linux - avatar
+ 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 }
22nd Dec 2022, 2:47 PM
Isak Nilsson
+ 2
public static void LoadingMessage(){
22nd Dec 2022, 2:49 PM
SoloProg
SoloProg - avatar
+ 2
Thank😊
24th Dec 2022, 2:20 PM
Fly King
Fly King - avatar