Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

grandM

macrumors 68000
Original poster
Oct 14, 2013
1,568
329
I have two separate files. In the file Dog I am attempting to subclass the class Animal. The code of the class Animal:
Code:
class Animal {

    var name = "animal"
    private var whatAnAnimalSays = "animal talk"
    func makeSound() {
        print(self.whatAnAnimalSays)
    }
}

The code of the class Dog being
Code:
class Dog: Animal {

    override var name = "dog"
    private var whatAnAnimalSays = "woof"
    override func makeSound() {
        print(self.whatAnAnimalSays)
    }
}

}

I have several questions:
1 I do not get an objection for the member whatAnAnimalSays. Is this because Dog doesn't know the member exists? For if the subclass Dog would know the member whatAnAnimalSays exists (being a subclass of Animal) I would have to use override?
2 I cannot override the member name (cannot override with a stored property 'name'). Why is that? The member name is internal so visible to all code. Shouldn't I be able to override it?

Thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.