This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes 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
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Question on interface inheritence

 
Greenhorn
Posts: 26
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a inheritance question. Here i have Interface I1 and I2 (that extends I1 and overrides its default method). In Class1 , i try to implement both I1 and I2 . Since I2 override I1's method. It inherited I2's overridden method and the Test class prints 2.

I expected it to give a compiler error in Class1 about inheriting duplicate method . But it did not .Can you please explain this a bit more ?

 
Ranch Foreman
Posts: 82
1
VI Editor Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is because interface I2 is overriding 'someMethod' from interface I1. I think that 'implements' statement for Class1 mentioning implementing interface I1 is redundant, since Class1 implements it implicitly via implementing interface I2, which is extending I1. Class1 would have compiler error stating that it should provide its own implementation of 'someMethod' method, if interface I2 would not be extending interface I1.
 
Rancher
Posts: 3570
38
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Namith Kumar wrote:I have a inheritance question.



When in doubt -- refer JLS 8-)

The JLS 11 has special explanation for this case - Section 9.4.1

Let me quote the relevant fragment:

Right inherits name() from Top, but Bottom inherits name() from Left, not Right. This is because name() from Left overrides the declaration of name() in Top.

Based on above, Class1 inherits someMethod() from I2, and there is no conflict (diamond inheritance)

 
Namith Kumar
Greenhorn
Posts: 26
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you @Miroslav Lehotsky & @Mikalai Zaikin.

Mikalai : Thanks for the link to JLS. Never though of looking there . I will go through it.
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!