Share this and super keyword in java

nguyenaipepper

New member
#Java #SuperKeyword #thiskeyword #Keyword #Javatutorial

## Các từ khóa này và siêu trong Java

Các từ khóa `this` và` Super` là hai trong số các từ khóa quan trọng nhất trong Java.Chúng được sử dụng để tham khảo đối tượng hiện tại và lớp cha của đối tượng hiện tại, tương ứng.

### Từ khóa này

Từ khóa `` này được sử dụng để chỉ đối tượng hiện tại.Nó có thể được sử dụng để truy cập các trường và phương thức của đối tượng hiện tại, cũng như gọi các hàm tạo của đối tượng hiện tại.

Ví dụ: mã sau in giá trị của trường `name` của đối tượng hiện tại:

`` `java
System.out.println (this.name);
`` `

Từ khóa `` này cũng có thể được sử dụng để gọi các hàm tạo của đối tượng hiện tại.Ví dụ: mã sau gọi `Super ()` Trình xây dựng của lớp `person`:

`` `java
người công cộng (tên chuỗi) {
Siêu (tên);
}
`` `

### Từ khóa siêu

Từ khóa `Super` được sử dụng để tham khảo lớp cha của đối tượng hiện tại.Nó có thể được sử dụng để truy cập các trường và phương thức của lớp cha, cũng như gọi các hàm tạo của lớp cha.

Ví dụ: mã sau in giá trị của trường `name` của lớp cha của đối tượng hiện tại:

`` `java
System.out.println (Super.Name);
`` `

Từ khóa `Super` cũng có thể được sử dụng để gọi các hàm tạo của lớp cha.Ví dụ: mã sau gọi `Super ()` Trình xây dựng của lớp `person`:

`` `java
sinh viên công khai (tên chuỗi) {
Siêu (tên);
}
`` `

## Bản tóm tắt

Các từ khóa `this` và` Super` là hai trong số các từ khóa quan trọng nhất trong Java.Chúng được sử dụng để tham khảo đối tượng hiện tại và lớp cha của đối tượng hiện tại, tương ứng.Các từ khóa này có thể được sử dụng để truy cập các trường, phương thức và hàm tạo của đối tượng hiện tại và lớp cha.

## hashtags

* Java
* Từ khóa siêu
* Từ khóa này
* Từ khóa
* Hướng dẫn Java
=======================================
#Java #SuperKeyword #thiskeyword #Keyword #Javatutorial

## The this and super keywords in Java

The `this` and `super` keywords are two of the most important keywords in Java. They are used to refer to the current object and the parent class of the current object, respectively.

### The this keyword

The `this` keyword is used to refer to the current object. It can be used to access the fields and methods of the current object, as well as to call the constructors of the current object.

For example, the following code prints the value of the `name` field of the current object:

```java
System.out.println(this.name);
```

The `this` keyword can also be used to call the constructors of the current object. For example, the following code calls the `super()` constructor of the `Person` class:

```java
public Person(String name) {
super(name);
}
```

### The super keyword

The `super` keyword is used to refer to the parent class of the current object. It can be used to access the fields and methods of the parent class, as well as to call the constructors of the parent class.

For example, the following code prints the value of the `name` field of the parent class of the current object:

```java
System.out.println(super.name);
```

The `super` keyword can also be used to call the constructors of the parent class. For example, the following code calls the `super()` constructor of the `Person` class:

```java
public Student(String name) {
super(name);
}
```

## Summary

The `this` and `super` keywords are two of the most important keywords in Java. They are used to refer to the current object and the parent class of the current object, respectively. These keywords can be used to access fields, methods, and constructors of the current object and the parent class.

## Hashtags

* Java
* super keyword
* this keyword
* keyword
* Java tutorial
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top