We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
No You can't do that because we need to reference the variables in main method,as main method is non-editable.so the only option you have that while compiling, when JVM loads (.class) file in the memory intialize all those variables at the same time that can be done when you declare variables as static.
Java Static Initializer Block
You are viewing a single comment's thread. Return to all comments →
No You can't do that because we need to reference the variables in main method,as main method is non-editable.so the only option you have that while compiling, when JVM loads (.class) file in the memory intialize all those variables at the same time that can be done when you declare variables as static.
Thanks, that helps a lot to understand how it works