• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

an object can call static method.

 
Ramakrishna Konanki
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even though you invoke the method with the object, the compiler implicitly do the rest!
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
Campbell Ritchie
Sheriff
Posts: 51461
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Ramakrishna" you have been warned before about your displayed name. Please read this.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic