• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

What class does my object extend?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic