What is the difference in Java static methods and non-static method is

The difference between static and non-static methods Method summarized as follows:
1, static method belong to the class of all, to use the front class instantiation;
2, non-static method can access any member of the class, static methods can only access a static class member ;
3, because the static method can be used before the class is instantiated, and the class must be non-static variables to allocate memory after instantiation;
! 4, only static internal static variables and other static methods and static methods also appear keywords like this can not be used because it belongs to the class as a whole;
5, examples of the shortcomings of high static methods than the method of static destruction efficiency is not automatic, but can be instantiated is destroyed;
6, static methods, and always use the same memory after static variables are created, using examples of the way will create more memory.
The main difference: the static method to create the object before you can use the non-static method must be called out by the new object.
Static methods and instance methods no significant difference in performance and memory footprint, whether declared as static method requires from the type of non-static fields, event, object-oriented extensions and polymorphism of these three aspects to consider.

Published 444 original articles · won praise 15 · views 10000 +

Guess you like

Origin blog.csdn.net/zt2650693774/article/details/104995979