OOP – Inheritance – Q&A

Question 1[2 marks]
Class File:​
   private filename​
   
   //Constructor for the File class
   procedure new(strFilename):​
      filename = strFilename​

   public procedure rename(strFilename)​
      if strfilename!="":​
         filename = strFilename​

Class MP3 inherits File:​
  private title​
  private artist​
  private duration​

  //Constructor for the MP3 class
  procedure new(strFilename, strTitle, strArtist, intDuration):​
     super.new(strfilename)​
     title = strTitle       ​
     artist = strArtist​
     duration = strDuration​

  public function getDuration():​
     min = duration // 60​
     sec = duration % 60​
     return (str(min) + ":" + str(sec))

What code would you write to instantiate one new MP3 object called topTrack for the latest 3 minutes 12 seconds song “Shivers” from Ed Sheeran?




Question 2[4 marks]

What are all the methods and properties of the MP3 class?




Question 3[4 marks]

Explain, using an example from this code, what is meant by inheritance?





Save / Share Answers as a link

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 4.8 / 5. Vote count: 24

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: , ,