wood burning stoves*
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interface inheritance" Watch "Interface inheritance" New topic
Author

Interface inheritance

Simon Edwards
Greenhorn

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?



Thanks.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10924
    
  12

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?



Thanks.


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().

Regards,
James.
Chintu Singh
Greenhorn

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.


OCPJP
Dan Drillich
Ranch Hand

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

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


when running -



Regards,
Dan


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: 607
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.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Interface inheritance
 
Similar Threads
constructor doubt
Looking for a strategy for solving upcasting/downcasting questions
Super class method
Private methods' inheritance
Exceptions (long one) Your response requested.