This question already has an answer here:
I have written the following code:
package staticshow;
public class StaticDemo {
static int a = 3;
static int b = 4;
static {
System.out.println("Voila! Static block put into action");
}
static void show() {
System.out.println("a= " + a);
System.out.println("b= " + b);
}
}
public class StaticDemoShow {
public static void main() {
StaticDemo.show();
}
}
I am getting the error message:
The public type StaticDemo must be defined in its own file
error in the very first line public class StaticDemo {
. Why is it happening and how can I resolve it? Note that my project name is StaticDemoShow
, package name is staticshow
and class names are as given in the code.
EDIT- After making just one class public or both the classes default, I am getting the error "Selection does not contain a main type". Now what should I do?