Scope and use of super keyword in Java

前端 未结 1 416
囚心锁ツ
囚心锁ツ 2021-01-29 16:25

Why can\'t I access the parent class variable with the super keyword?

With the below code, the output is:

feline cougar c c   


        
1条回答
  •  别那么骄傲
    2021-01-29 17:10

    The answer to the original question is simple: There is only one variable called type. Its initial value gets overwritten by c. Remember that there is only one object, so one variable. Prashant's code creates a second variable and obviously that one doesn't overwrite the original string in the parent class.

    0 讨论(0)
提交回复
热议问题