Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interface inheritance" Watch "Interface inheritance" New topic

Interface inheritance

Simon Edwards

Joined: Apr 01, 2013
Posts: 6
In the following code, does method row() in interface Derived overrides method row() in interface Base, or hides it?

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11689

What happened when you tried to implement both of these in the same class?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Zhenyi Luo
Ranch Hand

Joined: Sep 03, 2012
Posts: 33
Simon Edwards wrote:In the following code, does method row() in interface Derived overrides method row() in interface Base, or hides it?


I believe it is override.
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
Hi Simon Edwards,

here ther row() method in Base interface will be overriden by the Derived interface row().

Chintu Singh

Joined: May 08, 2013
Posts: 20
Yes, It is an override in Interface Derived.
When you try to implement both of these interfaces in same class, you cannot implement row() method with "throws Throwable". It should always be an Exception or a subclass of Exception.

Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
overrides, as the complier tells us the following -

public void row() throws Throwable {}
overridden method does not throw Throwable
1 error

when running -


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 909
Final3 is a child of Derived. A rule says that an overriding method cannot throw exceptions that is broader than its overridden method.
Throwable in Final3 is broader than Exception.
That is why it won't compile.

Look at this example:

Look at this bad example. This example illustrates why a child class cannot throw a broader exception.

Have you tried LearnNowOnline?
subject: Interface inheritance