Why do we have to call super in Android sometimes?

后端 未结 6 1066
暗喜
暗喜 2020-11-29 21:05

Sometimes when I override methods, I get an exception the first time it\'s called like below:

05-31 21:32:04.266: E/AndroidRuntime(28471): android.support.v4         


        
6条回答
  •  有刺的猬
    2020-11-29 21:39

    As a basic, super is a method used to refer the main superclass field/method from which class extension is done(using extends in the initial class definition) or whose instance is created from.

    When we need a most basic definition to be altered of the method/field of the superclass to be used to solve our purpose.

    for example

    java.lang.Object (has a lot of methods & fields) >android.view.View >android.view.ViewGroup >android.widget.LinearLayout

    But if you need to change/use as it is a method of the Object Class then you need the Super method to refer the first time created method in the object class within the LinearLayout class.

提交回复
热议问题