Home > Java > JavaBase > What do keywords mean in java

What do keywords mean in java

王林
Release: 2019-11-12 09:36:50
Original
13165 people have browsed it

What do keywords mean in java

What are keywords?

Keywords are words that are given specific meanings in the Java language and cannot be used as identifiers. There are two special keywords goto and const in java. We call these two keywords reserved words.

Common keywords:

(1)this keyword

this keyword Used to represent the current object itself, or an instantiated object of the current class. All properties and methods of the object can be called through this. The this keyword cannot be used in static methods.

Usage of this keyword:

1. The this keyword can be used to clearly access the member variables and member methods of a class and resolve conflicts with local variable names.

2. The this keyword calls the constructor: The constructor is automatically called by the Java virtual machine when instantiating the object. It cannot be called like a normal method. It can be called through this (parameter 1, parameter 2.. ...) calls other constructors.

3. This can also represent the current object, that is, which object is calling the method where this is located, then this represents this object at this time.

(2) super keyword

The super keyword represents the parent class object. It is mainly used to specify the attributes and methods of the parent class, and is also used in subclasses. Initialize the parent class. The super keyword cannot be used in static methods of subclasses.

Super keyword usage:

1. Use the super keyword to call the properties and methods of the parent class in the subclass. When the subclass and the parent class have the same properties and methods, At this time, if you want to call the properties and methods of the parent class, you must use the super keyword. If not used, the methods and properties of the parent class will be overridden by the subclass.

2. A subclass is a derived class of the parent class, and its instantiation depends on the instantiation of the parent class. Therefore, any of its constructors must initialize the parent class. In Java, the super keyword calls the parent class constructor to complete this operation. If there is no parameterless constructor in the parent class, then super must be explicitly called in the child class to call the existing parameterized constructor to initialize the parent class.

Recommended tutorial: java tutorial

The above is the detailed content of What do keywords mean in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template