• 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

why, if one method is declared as abstract, the same cannot be declared as static ?

 
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why, if one method is declared as abstract cannot be declared as static ?
i m talking about interface in which methods are implicitly abstract and that method cannot have static modifier ? why so ?
 
Bartender
Posts: 4568
9
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marking a method abstract means that you will override it in a sub-class and provide the implementation. A static method cannot be overridden, so it would be impossible to provide the implementation of a static abstract method. So it makes no sense to allow it.
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:Marking a method abstract means that you will override it in a sub-class and provide the implementation. A static method cannot be overridden, so it would be impossible to provide the implementation of a static abstract method. So it makes no sense to allow it.


static method cannot be overriden because those methods are for that particular class ?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naved momin wrote:static method cannot be overriden because those methods are for that particular class ?


Please, SearchFirst
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naved momin wrote:

Matthew Brown wrote:Marking a method abstract means that you will override it in a sub-class and provide the implementation. A static method cannot be overridden, so it would be impossible to provide the implementation of a static abstract method. So it makes no sense to allow it.


static method cannot be overriden because those methods are for that particular class ?


Static members are shared among all instances of a class -- one might say, independently of its instances.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naved momin wrote:

Matthew Brown wrote:Marking a method abstract means that you will override it in a sub-class and provide the implementation. A static method cannot be overridden, so it would be impossible to provide the implementation of a static abstract method. So it makes no sense to allow it.


static method cannot be overriden because those methods are for that particular class ?



They cannot be overridden because the language designers decided to make it that way. In some languages (like SmallTalk, I think), static methods can be overridden. Java's designers had a different model in mind for class, objects, and polymorphism. It was a language design choice. If you want to know why that choice was made, you'd have to ask them, or see if it shows up in a whitepaper somewhere. A good guess, though, would be that it keeps the language simpler. Simplicity has always been one of Java's key goals.
 
It's feeding time! Give me the food you were going to give to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic