I have two separate files. In the file Dog I am attempting to subclass the class Animal. The code of the class Animal:
The code of the class Dog being
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!
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!