What is super () in Java

Source: Internet
Author: User
To say super is to say this first.


2. Can be used inside a non-static member of a class to represent the current object. At this point, this is a final normal variable, which has a static type, which is the class C itself; it has a dynamic type, which is the type of the current object. You can call member functions on it, pass it to other functions, and so on. As long as a final variable of type C can appear, it can appear.


1. Represents the constructor that invokes the parent class. is also a special syntax, not a variable, no type.


However, note that this super.method () is just as long as Some_var.method (), a syntactic sugar. In essence, "Super" is not a variable at all.


So, if super is a variable that also points to the current object, then whatever the static type of super is, Super.method () is bound to call the version of the subclass, not what we expected, but statically select the version of the parent class.

So, you just have to think of super.xxx as a special grammar, such as "super::xxx".

Since super is not a variable, it's not as "= =" as a normal variable, or it seems normal to pass it to a function, right? Besides, you don't really need it, you can do it with this.

3. Another function of super is to call the parent class's protected function. Only through the magic of "super" can we manipulate the protected members of the parent class, and there is no other way.
This answer is recommended by the questioner

What is super () in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.