public static void main(String []args){ Example.A(); // line 1 } }
this runs fine. tell me how can be a static method of the class Example is called by the name of class only. i.e. (Same in the case of Math class) Why there is no need to create explicit object of Example class?
Perform for today. Adapt for tomorrow.
Chandra Bhatt
Ranch Hand
Joined: Feb 28, 2007
Posts: 1707
posted
0
class Example{
static A(){ // somthing }
public static void main(String []args){ Example.A(); // line 1 } }
this runs fine. tell me how can be a static method of the class Example is called by the name of class only. i.e. (Same in the case of Math class) Why there is no need to create explicit object of Example class?
Error in code: there is no return type of static method A(). Fix it!
static methods are called class level methods. You think about main() method, do you ever need to create an instance of the class to call the main() method; NO! You need not to create an instance of the class to call its static methods. Although it you use the class reference variable to access it, it is provided;
Thanks and Regards, cmbhatt
cmbhatt
Rahul Shilpakar
Ranch Hand
Joined: Aug 29, 2006
Posts: 132
posted
0
wow, it was nice explaination. thank you very much.