The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Abstract classes/Interfaces ... a usage question

Posted by John Dell'Oso on January 08, 2001 at 11:35 PM

I'm fairly new to the world of Java.

I understand to a reasonable degree what abstract classes and interfaces are and do. However, with a particular Java text (Java Bible in fact) I'm working through, I see examples of usage that perplex me.

For example, with the abstract class InputStream, an example in the book uses a class that uses InputStream to define what I think is an object reference called "in".

Another example is the interface AudioClip - an example in the book declares a reference of type AudioClip called "myAudio" and then happily uses the interfaces' methods called loop() and stop() - and the snippet works fine.

My question - how is all this possible ? With an abstract class, you can't instantiate, you can only extend, however the first example doesn't use an "extends" clause on it's class definition - it just says InputStream in, and chugs along nicely.

With the AudioClip interface, the sample code declares "Audioclip myAudio" and uses method calls myAudio.loop() and myAudio.stop() which are two of the three required methods that need to be implemented for interface AudioClip (what happens to the implementation of the method play()?). The class definition does not "implement" the methods of the AudioClip interface. So what is going on here? Where are the methods being implemented ?

Sorry for the verbosity of my question - I would really appreciate it if someone could explain this a whole lot better than my text book attempts to do (in fact, it doesn't explain it at all).

Thanks and regards,

John Dell'Oso


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us