Swift: Simple inheritance with a method

This is an inherited class with a call to the parent’s method.

class Person {
    var name = ""
    var age = 0
    
    init(){
        self.name = ""
        self.age = 0
    }
    
    init(name:String,age:Int){
        self.name = name
        self.age = age
    }
    
    func printIntro(){
        print("My name is \(self.name) My age is \(self.age)")
    }

}


class Student : Person {
    
}

var student = Student(name: "Taylor Swift", age: 20)

student.printIntro()

swift

Series Navigation<< Swift: Printing an incrementing number
Swift: A struct with a closure >>