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 を親クラスのプロパティ one に追加したい

また、すべてのサブクラス variableTwo を親クラス two に追加したい

4

0 に答える 0