
public class Sample{
public static void main(String args[]){
int a;
}
}
Q.why the above code is not compiled ?
Q.why the below code is compiled successfully ?
public class Sample{ public static void main(String args[]){ int a; String s="hajju"; } }

Both are compiled here successfully. The code should be compiled as there is no error in code, you have created a class Sample and in main method, you have declared a variable. Everything is fine.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.