In: Computer Science
This is for C++
A static main() function defined in your homework assignments
means:
1.The function is always invisible to all functions outside of the class.
2.The function cannot declare any variables.
3.The function can be called without an instance.
4.The function can access all variables and methods.
5.The function can be called by the superclass.
Ans would be 3.The function can be called without an instance.
Option 1. Is incorrect because Static function() is not invisible to all the function outside the class, infact it can be accesed anywhere in the program scope using scope resolution operator with the class name.
Option 2 Is incorrect because a static function can declare its own variable, but cannot access non static variable of its own class.
Option 4. Is incorrect because a static function can only access static variable of its class.
Option 5. Is incorrect because a superclass object can not call a static function direclty as it is not defined/declared in the superclass scope, although vice versa is true and static method of super class can be called from derived class.
Explanantion:
By declaring a function member as static, you make it independent of any particular object of the class. A static member function can be called even if no objects of the class exist and the static functions are accessed using only the class name and the scope resolution operator ::.
A static member function can only access static data member, other static member functions and any other functions from outside the class.Static member functions have a class scope and they do not have access to the this pointer of the class. You could use a static member function to determine whether some objects of the class have been created or not.