Win a copy of Java Challengers this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

"Instantiating" an object of an abstract class

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator





A bit confused here.

My assignment requires that I "test MusicMedia objects" in my test function of my Main program. I am aware that I'm trying to instantiate an object of an abstract class which is giving me an error. Is there anyway I can "create" MusicMedia objects and test the methods within in that class as well as print out the toString() function?

Thank you!
 
Marshal
Posts: 26531
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need subclasses which provide implementations of the abstract methods, i.e. simply the play() method. Objects of those subclasses can be created and are "MusicMedia objects".

If you're only concerned with the toString() method for now, the implementation of the play() method doesn't have to do anything useful, or indeed anything at all. It just has to exist.
 
Marshal
Posts: 72657
317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...in which case, let me suggest the skeleton implementation you would get from NetBeans:-That will compile easily and won't allow you to run a method before it has been completely implemented.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic