• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

inheriting interfaces

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Does a subclass inherit the interfaces that base classes implements?

In particular, if I have a base class implementing 'Serializable', does subclass automatically implement it?

Thanks,
P Ingle
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, welcome to the ranch! In this forum we often encourage you to answer your own questions a little bit at a time. For this one, why not just try it? Make an interface I with one method, a class A that implements I and a class B that extends A. Then see if ( B instanceOf I ).

Also try saying "A implements I" but don't actually code the required method in A. What does the compiler tell you then?

Don't be discouraged by this answering a question with a question. Or two. We really want you to have the joy of working things out. They'll stick in your head much better that way! Let us know what you find and whether it makes sense.
 
P. Ingle
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestion. My qusetion was related to serializable (or similar) interface that does not have any method of it's own. I have BaseClass inplementing Serializable and SubClass extending BaseClass. So how do I make sure that SubClass really is serializable.

I took your suggestion and tried with following classes:


public interface TempI {
public void tempMethod();

}

<B>
// I made BaseClass abstract so compiler did not complain even if I didn't
// have implementaion of tempMethod()
</B>

public abstract class BaseClass implements TempI {

}

<B>
//If I remove tempMethod() from SubClass, compiler complains
// so I know for sure that it is indeed implementing
// interface TempI
</B>

public class SubClass extends BaseClass {


/* (non-Javadoc)
* @see testTemp.TempI#tempMethod()
*/
public void tempMethod() {
// TODO Auto-generated method stub

}

Thanks,
P Ingle
 
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks for the suggestion. My qusetion was related to serializable (or similar) interface that does not have any method of it's own. I have BaseClass inplementing Serializable and SubClass extending BaseClass. So how do I make sure that SubClass really is serializable.


Serializable is a 'tag' interface; it doesn't contain any methods, it is just used to indicate to the system that this class should be Serializable. However it behaves in exactly the same way as other interfaces, so your subclass will indeed be Serializable if the base class is.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
P. Ingle
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by marc weber:



Cool, it made it explicitly prooved to me that the subclass does implement serializable - Thanks,
P Ingle
 
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic