Get the App
SLTechnology News&Howtos  ›  Development  › 

The difference between the usage of java basic knowledge super and this

Shulou Source: shulou.com Published: 2022-06-03 14:05:49 11月01日 Update

The main content of this article is to explain the difference between the usage of java basic knowledge super and this. Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the difference between the usage of java basic knowledge super and this.

There are three uses of the super keyword:

1. In the member method of the subclass, access the member variable of the parent class

2. In the member method of the subclass, access the member method of the parent class

3. In the constructor of the subclass, access the constructor of the parent class

The difference between this and super

The super keyword is used to access the parent content, and the this keyword is used to access the content of this class.

1. In the member methods of this class, access the member variables of this class

2. In the member method of this class, access another member method of this class

3. In the constructor of this class, access another constructor of this class

Note in the third usage:

A, this (...) The call must also be the first statement of the constructor, the only one

B, super and this construction calls cannot be used at the same time.

This method is called by default if public class Zi extends Fu {int num = 20; public Zi () {/ / super (); / / does not write. This (111n); / / No parameter construction of this class. Call the parameter construction of this class} public Zi (int n) {this (1p2);} public Zi (int n, int m) {} public void methodZi () {System.out.println (super.num); / / num} public void method () {super.method () in the parent class; / / method System.out.println of the parent class ("subclass method");} public void showNum () {int num = 10 System.out.println (this.num); / / 20}}

At this point, I believe you have a deeper understanding of "the difference between the usage of java basic knowledge super and this". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Methods members content subclasses basics basics knowledge keywords keywords variables learning practical deeper interest at the same time practicality practicality simple operation more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Information NVidia OPPO Reno Xiaomi