O'Reilly logo

Learning iOS Development: A Hands-on Guide to the Fundamentals of iOS Programming by Erica Sadun, Rod Strougo, Maurice Sharp

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Subclassing and Inheritance: A Challenge

While gas and diesel cars continue to improve their use of fuel, your customers are demanding that you model a hybrid car. Your job is to create a HybridCar class that inherits from Car and adds a method to return the number of miles until the car’s battery and fuel are empty. You can name this method –(float)milesUntilEmpty.

Hint

Don’t forget to track the miles per gallon (MPG) so you can calculate the distance until the car is empty. For example, the 2013 Toyota Prius hybrid gets 42MPG. If there were 10 gallons left in the tank, the car would have a theoretical range of 402 miles until the tank was empty.

Think about it for a few minutes.

Do you have a solution worked out?

Go to the following section ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required