• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Static And Default Methods in Interfaces  RSS feed

 
Greenhorn
Posts: 14
  • 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: 64100
215
  • 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: 14
  • 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: 64100
215
  • 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: 14
  • 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 )
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!