There are two very special variables in Java: this and super. These two variables do not need to be declared before use. This variable is used inside a member function and points to the current object. The current object refers to the object that calls the currently executing method. The super variable points directly to the constructor of the super class and is used to reference variables and methods in the super class. So they are all very useful variables. Now I would like to introduce how to use this and super.
1. this
Let us look at a piece of code first:
class PersonInformation
{
String name,gender,nationality,address;
int age;
void PersonInformation(String p_name,String p_ gender,String p_nationality,String p_address,int p_age)
{
name=p_name;
gender=p_gender;
nationality=p_nationality;
address=p_address;
age=p_age ;
}
}
You You will find that the method prompt of this object in the PersonInformation() function can directly access the member variables of the object, and it is not allowed to define two local variables with the same name in the same scope. If you really want to make the class If a member variable has the same name as a method parameter or a local variable defined by the method itself, you need to think of a way to distinguish the member variable from the method parameters or local variables with the same name. This requires the use of the this variable. Now I want to rewrite the above code so that each parameter of the constructor of the PersonInformation class has the same name as the object member variable, and the initial value of the member variable is given by the parameter.
class PersonInformation
{
String name, gender, nationality, address;
int age;
this. name = name; It can be seen that this must be used in the constructor. This is used in the method body to point to the object instance that refers to the currently executing method. The type of this variable is always the class containing the previously executed method. In the above example, we need to distinguish It is obviously not allowed to write parameter name and member variable name as name=name. When the parameter or local variable name has the same name as the class member variable, because the parameter or local variable has a high priority, the parameter name or local variable in the method body The variable name will hide the member variable with the same name. Therefore, to value the member variable, you must use this to explicitly indicate the current object.
Sometimes we encounter this situation. We fully access the current object instead of accessing an individual instance object. We can also use this and use the toString() method in Java (it can return a description of this Object's string) If any object is passed to the System.out.PRintln method, this method calls the toString method of this object and prints out the result string. Therefore, we can use the following method System.out.println(this ), to print out the current status of any intrinsic method parameters.
There is another usage of this, which is the first statement of the constructor. Its form is this (parameter list). This constructor will call another relative constructor of the same class. Please see the following example:
class UserInfo
{
public UserInfo(String name)
{
this(name,aNewSerialNumber);
}
public Userinfo(String name,int number)
{
userName=name;
userNumber=number;
}
}
If you call UserInfor newinfotable = new UserInfo("Wayne Zheng"), UserInfo(String) will be called automatically.
The above is in Java For the contents of the two special variables this and super, please pay attention to the PHP Chinese website (www.php.cn) for more related articles

本站1月6日消息,技嘉的RTX4080SUPER、RTX4070TiSUPER和RTX4070SUPER显卡已经曝光,预计1月9日0点发布。如上图所示,英伟达RTX40SUPER显卡的logo发生了变化,SUPER全大写,而RTX20系列的则是小写的super。RTX20superlogo本站汇总RTX40SUPER显卡爆料规格和价格如下:RTX4080SUPER配备10240CUDA核心和16GB23Gbps256bitGDDR6X显存,999美元(当前约7153元人民币)或1199美元(当前

一、static 请先看下面这段程序:publicclassHello{publicstaticvoidmain(String[]args){//(1)System.out.println("Hello,world!");//(2)}}看过这段程序,对于大多数学过Java的从来说,都不陌生。即使没有学过Java,而学过其它的高级语言,例如C,那你也应该能看懂这段代码的意思。它只是简单的输出“Hello,world”,一点别的用处都没有,然而,它却展示了static关键字的主

同事因为this指向的问题卡住的bug,vue2的this指向问题,使用了箭头函数,导致拿不到对应的props。当我给他介绍的时候他竟然不知道,随后也刻意的看了一下前端交流群,至今最起码还有70%以上的前端程序员搞不明白,今天给大家分享一下this指向,如果啥都没学会,请给我一个大嘴巴子。

本篇文章带大家解读vue源码,来介绍一下Vue2中为什么可以使用 this 访问各种选项中的属性,希望对大家有所帮助!

一、this关键字1.this的类型:哪个对象调用就是哪个对象的引用类型二、用法总结1.this.data;//访问属性2.this.func();//访问方法3.this();//调用本类中其他构造方法三、解释用法1.this.data这种是在成员方法中使用让我们来看看不加this会出现什么样的状况classMyDate{publicintyear;publicintmonth;publicintday;publicvoidsetDate(intyear,intmonth,intday){ye

什么是this?下面本篇文章给大家介绍一下JavaScript中的this,并聊聊this在函数不同调用方式下的区别,希望对大家有所帮助!

supersuper是一个关键字,全部小写。super和this对比着学习,都是"this/super."出现在实例方法,“this/super()"出现在构造方法当中this:(1)this能出现在实例方法和构造方法中。(2)this的语法是:“this.”、“this()”(3)this不能使用在静态方法中。(4)this.大部分情况下是可以省略的。(5)this.什么时候不能省略呢?在区分局部变量和实例变量的时候不能省略。publicvoidsetName(S

jQuery是一种流行的JavaScript库,广泛用于网页开发中的DOM操作和事件处理。其中一个重要的概念就是this关键字的使用。在jQuery中,this代表当前操作的DOM元素,但在不同的上下文中,this的指向可能会有所不同。本文将通过具体的代码示例来解析jQuery中this的使用技巧。首先,让我们来看一个简单的示例:


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.