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

前端 未结 9 1845
你的背包
你的背包 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:37

    super is used to access methods of the base class while this is used to access methods of the current class.

    Extending the notion, if you write super(), it refers to constructor of the base class, and if you write this(), it refers to the constructor of the very class where you are writing this code.

提交回复
热议问题