| Author |
an object can call static method.
|
Ramakrishna Konanki
Greenhorn
Joined: Apr 18, 2008
Posts: 20
|
|
in the site mock example i have seen code
like
an object can call static method.
as i've studied static members should be called with class name.
please justify the solution
|
 |
Harnoor Singh
Ranch Hand
Joined: Aug 24, 2010
Posts: 35
|
|
Lets us say we have class with name Har which has static method with name stat. We can call stat by following 2 ways :-
1)Har.stat();
2)obj.stat();--> where obj is object of class Har
Though both are allowed by compiler , but option 2 is discouraged.
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
|
Even though you invoke the method with the object, the compiler implicitly do the rest!
|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1046
|
|
An static method can be called by a object,there is no problem but the code will compile with warning saying
static method should be accessed in a static way
|
SCJP6.0,My blog Ranchers from Delhi
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32611
|
|
|
"Ramakrishna" you have been warned before about your displayed name. Please read this.
|
 |
 |
|
|
subject: an object can call static method.
|
|
|