Java abstract class fields override

后端 未结 6 937
春和景丽
春和景丽 2020-12-06 11:34

I have an abstract class that should implement a public field, this field is an interface or another abstract classe.

something like this:

public abstr         


        
6条回答
  •  时光取名叫无心
    2020-12-06 12:03

    In Java, data members/attributes are not polymorphic. Overloading means that a field will have a different value depending from which class it's accessed. The field in the subclass will hide the field in the super-class, but both exists. The fields are invoked based on reference types, while methods are used of actual object. You can try it yourself.

    It's called, variable hiding/shadowing, for more details look on here

提交回复
热议问题