0
class example {    //parent class
    var one:Int = 10  //i want all subclass variableOne to be added to this
    var two:Int = 20  //i want all subclass variableTwo to be added to this

    init () {
    }
}

class subClassOne : example {  //subclass one
    var variableOne:Int = 30  //properties i want to add to parent properties
    var variableTwo:Int = 30  //properties i want to add to parent properties

    override init () {
        super.init ()
        super.one = one + variableOne
        super.two = two + variableTwo
    }
}

class subClassTwo {
    var variableOne:Int = 20  //properties i want to add to parent properties
    var variableTwo:Int = 20  //properties i want to add to parent properties

    override init () {
        super.init ()
        super.one = one + variableOne
        super.two = two + variableTwo
    }
}

我希望将所有子类 variableOne 添加到父类属性一

我还希望将所有子类 variableTwo 添加到父类 2

4

0 回答 0