Extending a class using an extension

Just as you saw with structs, classes can be re-opened using the extension keyword to add methods and computed properties. Add a fullName computed property to Student:

extension Student {

var fullName: String {

return "(firstName) (lastName)"

}

}

Functionality can also be added to classes using derivation. You can even add new stored properties to derived classes. You will explore this technique in detail in the next chapter.

results matching ""

    No results matching ""