• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About static

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why cant we declare a method as static as well as abstract.What exactly happens when static blocks gets executed during run time.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you declare method as abstract you are declaring that it should be overriden by the concrete subclass.



You can then have code like


Static methods are defined on a class and can not be overriden. They can only be hidden. If doSomething in the examples above was static. The last code example would have no meaning as while B.doSomething() has meaning, A.doSomething() does not.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you call non-static method, which method is really called depends on contents of object you call it on.
If object is an instance of one derived class, method defined for that class will be called. If you call it on instance of another class - another class will be called. Class of object isn't always known at call site, so code actually accesses object method called on.
So as you call static methods without any specific object, there's no information to decide based on which method is to call.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic