Where did I go wrong? | SoloLearn: Learn to code for FREE!


Where did I go wrong?

I have a code and I’m trying to figure out what I did wrong flit keep getting an error? https://code.sololearn.com/cYstVzPmc7jx/?ref=app

11/11/2019 8:37:24 PM

amill stacks

3 Answers

New Answer


amill stacks This time only. You have covered enough java course to fix the errors yourself ! public class A { static { vSystem.out.println("1"); int i = 100; } public static void main(String[] args) { //static int i; can't use static here // it should be int i; /* can't use static block here move it outside the main. static { System.out.println("1"); int i = 100; } */ } // <-- this closing bracket was missing } // this is a closing bracket for class public class StaticInitializationBlock { static { System.out.println("2"); } public static void main(String[] args) // ; <-- this semicolon is making main without body { System.out.println("3"); System.out.println("A,i"); } }


You cannot declare a variable explicitly static inside a static function. The sames goes for the static block inside a static function. In first class, main method is missing a closing '}' bracket. In the second class, there is a semicolon at the end of main function, making main without a body.


ok so im new to all this could you show me what you mean