• Post Reply Bookmark Topic Watch Topic
  • New Topic

What class does my object extend?  RSS feed

 
Jeff Tennenbaum
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I'm going through the HeadFirst Java book, which really is excellent. In the book, I am working on chapter 11 page 324 where we enter the lines
Sequencer player = MidiSystem.getSequencer();
player.open();
To better understand this line, I took a look at the javadocs associated with Sequencer and MidiSystem. The javadocs indicate that Sequencer is an interface and that getSequencer is a static method of the MidiSystem class.
My question is what type of an object is player?
I would say that player implements Sequencer but what object does it extend, does it extend MidiSystem? If so does getSequencer call new under the covers? Thanks in advance!!
Best Regards,
Jeff
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is what type of an object is player?
I would say that player implements Sequencer but what object does it extend, does it extend MidiSystem? If so does getSequencer call new under the covers?

Welcome to JavaRanch, Jeff!
player is an object of type Sequencer. Since Sequencer is an interface, player must also be of some other type. If you were to print out the result of a call to player.getClass() it should reveal other type information.
I'm not sure what getSequencer does, it might return a reference to an already existing instance of Sequencer, or it might create a new one.
If the concepts of polymorphism (which this is an example of) are at all unfamiliar, or just for a better understanding, you might enjoy a read of the "How my Dog learned Polymorphism" JavaRanch Campfire Story. It's from one of the same authors as the book you're reading.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!