What is static method? Explain why main method in java is always static?
Can any one explain What is static method? Explain why main method in java is always static?
When a normal member function is called, a pointer to the class instance ("this") is pushed onto the stack so that the function knows which object it needs to modify. A static member function doesn't have "this" passed to it, so it can only access other static members of the class.
The "main" method in java always has to be static because no objects have been created yet.
Reply:A static method is owned by a class rather than by instances of that class. The main method in Java is static so the JVM can start the class without creating an instance of the control class first.
garden sheds
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment