Understanding the behavior of the static is very important for the Java Base!

Ziplok

When I was learning Java, I always get confused what static variables and static methods mean. I read a lot of books explaining static and still it’s not clear to me. Let’s consider the “Hello World” class and program in Java.


and consider the following class,

Are these two classes the same?  Of course, they are not the same. The first class has a static keyword in its main method and the other one is simply a method without this keyword static.As always Java follows this signature in the first class. And we consider this as a complete and a running program in Java. The static main method means that all objects created out from this class has only one method main. And you can call main method without instantiating the class and directly invoke this method with the name of the class (HelloWorld.main()).All instance variables and methods of…

View original post 128 more words

Advertisements