In: Computer Science
can someone tell me why I'm getting the error code on Eclipse IDE:
Error: Main method is not static in class
StaticInitializationBlock, please define the main method as:
public static void main(String[] args)
This is what I'm working on
class A
{
static int i;
static
{
System.out.println(1);
i = 100;
}
}
public class StaticInitializationBlock
{
static
{
System.out.println(2);
}
public static void main(String[] args)
{
System.out.println(3);
System.out.println(A.i);
}
}
YOu need to saved the file as same name of public class that is StaticInitializationBlock.java
then copy the class A below it i managed to run on browxy just copy paste the below code and save as above name.
//start
public class StaticInitializationBlock
{
static
{
System.out.println(2);
}
public static void main(String args[]){
System.out.println(2);
System.out.println(A.i);
}
}
class A{
static int i;
static{
System.out.println(1);
i=100;
}
}
//end
//SCREENSHOT
Please comment below if you are still facing any problems.. I will get back to you asap...