Difference between “this” and“super” keywords in Java

前端 未结 9 1822
你的背包
你的背包 2020-11-27 03:00

What is the difference between the keywords this and super?

Both are used to access constructors of class right? Can any of you explain?

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 03:43

    this refers to a reference of the current class.
    super refers to the parent of the current class (which called the super keyword).

    By doing this, it allows you to access methods/attributes of the current class (including its own private methods/attributes).

    super allows you to access public/protected method/attributes of parent(base) class. You cannot see the parent's private method/attributes.

提交回复
热议问题