Comparison of this and super

2. Comparison of this and super

this: a reference to the object of this class    

super: a reference to the parent class in the object of this class

this and super
this. The property name accesses the member variable of this class
this. The method name (parameter) accesses other methods of this class

this (parameter) to access other constructors of this class (note that it must be used in the first line of the constructor) (just understand)


super. attribute name access parent class member variable (non-private)
super. method name (parameter) access parent class member method (non-private)
super (parameter) access parent class constructor (non-private) (note that it must be in the first part of the constructor Use one line)

Note: when this and super call the constructor, they cannot be used in the same constructor , because both need to be defined on the first line. When calling the constructor, you must ensure that the constructor can be called, if there is no such constructor, it cannot be called.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324476044&siteId=291194637