Code Monkey home page Code Monkey logo

objc-petcast's Introduction

PetCast

Instructions

  1. Create a class called FISPet. FISPet has a method called makeASound that returns an NSString that reads "Pet me!" It also has a method called eatSomething that returns an NSString that reads "Nom nom nom."

  2. Create a second class called FISDog. FISDog should be a subclass of FISPet. The FISDog class should override makeASound to return "Woof!" Also, FISDogs are able to assaultTheMailman. This method returns an NSString that reads "I got the mail! I got the mail!"

  3. In your FISAppDelegate application:didFinishLaunchingWithOptions:, create an instance of FISDog. Then...

    • Confirm that it barks and can assault the mailman!
    • Cast it to an FISPet and confirm that, even though the variable is now an FISPet, its makeASound still goes "Woof."
    • Create an instance of FISPet. Cast it to be an FISDog, and make it go "Pet me!" Can you call assaultTheMailman on this fake dog? Will it compile? Will it run?
    • Now try to make your FISDog that was cast as an FISPet assault the mailman. What happens? How might you make the method call work? See the hint below for more information.

Hint

It is possible to cast in-line by putting parentheses around an object. For instance, assume we had a FISCar class and a FISPorsche subclass, and the FISPorsche object had a property called isTurboCharged. The following would work:

FISCar *newCar = [[FISPorsche alloc] init];
((FISPorsche *)newCar).isTurboCharged = YES;

So, what is happening above? First, we have intialized a FISPorsche, but it has been assigned to a variable of type FISCar. Then when it is time to set the isTurboCharged property, we have re-cast newCar to its original FISPorsche type, so the compiler will let us access its isTurboCharged property. Note the extra set of parentheses before .isTurboCharged.

View PetCast on Learn.co and start learning to code for free.

objc-petcast's People

Contributors

annjohn avatar fislabstest avatar fs-lms-test-bot avatar ipc103 avatar markedwardmurray avatar misterfifths avatar zdrossman avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

amyjoscelyn

objc-petcast's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.