This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Static And Default Methods in Interfaces  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone ,

I have  one question  it is a little confusing for me :

Wthin the interface static method could  be at the same time default method ?

I think that it is not possible .even i write  in the compiler  and i saw  error

But  Why Java doesn't allow this scenario?
 
Marshal
Posts: 61805
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked in the Java® Language Specification (=JLS) about interfaces and about inheritance? The idea behind static methods is that they be called on the type not an object, so they are not inherited by implementing classes. Default methods are intended to be instance methods are are inherited with the condition that overriding is permitted if necessary. Now tell us how you want to make a method both static and default.
 
Darya Naghiyev
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Have you looked in the Java® Language Specification (=JLS) about interfaces and about inheritance? The idea behind static methods is that they be called on the type not an object, so they are not inherited by implementing classes. Default methods are intended to be instance methods are are inherited with the condition that overriding is permitted if necessary. Now tell us how you want to make a method both static and default.




i confused default and static access modifiers  with static and default method .
 
Campbell Ritchie
Marshal
Posts: 61805
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Darya Naghiyev wrote:. . . i confused default and static access modifiers  . . .

But default and static aren't access modifiers; only private protected and public are access modifiers. You need much more revision before you sit the exam.
 
Darya Naghiyev
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Darya Naghiyev wrote:. . . i confused default and static access modifiers  . . .

But default and static aren't access modifiers; only private protected and public are access modifiers. You need much more revision before you sit the exam.



i am just  in a bad mood  , anyway you are absolutely right )
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!