Home Java javaTutorial Object-oriented (inner class, static, package, access modifier, final)

Object-oriented (inner class, static, package, access modifier, final)

Jun 26, 2017 am 11:15 AM
static object access For

final
final is the final modifier, which can modify classes, member methods, and variables.
Final modified classes cannot be inherited.
Final modified methods cannot be overridden.
Final modified variables cannot be assigned again and become constants.

The reference data type variable modified by final can modify the attribute content in the object, but the address value cannot be changed
The member variable modified by final cannot use the default value, which is meaningless. The assignment must be completed before creating the object. .
Naming rules for constants All letters are capitalized. Multiple words are connected with _

static
Static modifier, the content modified by static belongs to the class and does not belong to an object , multiple objects share this member
Members modified with static can be directly accessed using the class name. It is recommended to use it like this:
Class name. Static method name (parameter);
Class name. Static attribute name ;
Static modified members can only directly access statically modified members, this and super cannot appear, because classes are superior to objects.
Static Notes
Static modified members are loaded with the class Loading takes precedence over object existence.
Static can only access static, and cannot use this/super

Static constant:static final

Local code block: limit the scope of the variable
Member code block: and Called construction code block, it will be executed as long as the object is created
Static code block: loaded as the class is loaded, the class is only loaded once and the code is loaded once
Loading of class: Create object, access static member variables, access static Method
Static code block>Member code block>Constructor method

The concept of internal class
A class defined inside a class is called an internal class. It is divided into: Member inner class and local inner class

Anonymous inner class
is a kind of local inner class
Anonymous inner class accomplishes two things:
1: Defined Anonymous subclass of a type
2: After defining the class, the object of the class is created immediately

Purpose: To create a subclass object of a certain class
Format: new parent class/interface () {
Overriding method
};

Package
The basic way for software to organize files, used to organize files Classes with the same functions are placed under the same package to facilitate management
Use package at the front of the class to define the package where the class is located. Note: the declared package must be consistent with the folder where the file is located
Package access: (The prerequisite class is modified with public)
Under the same package, you can access it at will
Under different packages:
You can use the full name directly
For convenience, you can choose to import the package and then use the class name directly itself, without adding the package name. After package, use import before class to import the class
If it is a class under the lang package, you can directly use

Access permissions
All four permissions in the same class can be accessed
Irrelevant classes under the same package can only be accessed by private
Irrelevant classes under different packages can only be accessed by public
Subclasses under different packages cannot be accessed by default and private access

The above is the detailed content of Object-oriented (inner class, static, package, access modifier, final). For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

iOS 17: How to control which apps can access your photos iOS 17: How to control which apps can access your photos Sep 13, 2023 pm 09:09 PM

In iOS17, Apple has more control over what apps can see in photos. Read on to learn how to manage app access by app. In iOS, Apple's in-app photo picker lets you share specific photos with the app, while the rest of your photo library remains private. Apps must request access to your entire photo library, and you can choose to grant the following access to apps: Restricted Access – Apps can only see images that you can select, which you can do at any time in the app or by going to Settings &gt ;Privacy & Security>Photos to view selected images. Full access – App can view photos

Convert an array or object to a JSON string using PHP's json_encode() function Convert an array or object to a JSON string using PHP's json_encode() function Nov 03, 2023 pm 03:30 PM

JSON (JavaScriptObjectNotation) is a lightweight data exchange format that has become a common format for data exchange between web applications. PHP's json_encode() function can convert an array or object into a JSON string. This article will introduce how to use PHP's json_encode() function, including syntax, parameters, return values, and specific examples. Syntax The syntax of the json_encode() function is as follows: st

How to access JSONNode's JSON fields, arrays and nested objects in Java? How to access JSONNode's JSON fields, arrays and nested objects in Java? Aug 30, 2023 pm 11:05 PM

A JsonNode is Jackson's JSON tree model that can read JSON into JsonNode instances and write JsonNode into JSON. We can use Jackson to read JSON into a JsonNode by creating an ObjectMapper instance and calling the readValue() method. We can access fields, arrays or nested objects using the get() method of the JsonNode class. We can use the asText() method to return a valid string representation and convert the node's value to Javaint using the asInt() method of the JsonNode class. In the example below we can access Json

Access metadata of various audio and video files using Python Access metadata of various audio and video files using Python Sep 05, 2023 am 11:41 AM

We can access the metadata of audio files using Mutagen and the eyeD3 module in Python. For video metadata we can use movies and the OpenCV library in Python. Metadata is data that provides information about other data, such as audio and video data. Metadata for audio and video files includes file format, file resolution, file size, duration, bitrate, etc. By accessing this metadata, we can manage media more efficiently and analyze the metadata to obtain some useful information. In this article, we will take a look at some of the libraries or modules provided by Python for accessing metadata of audio and video files. Access audio metadata Some libraries for accessing audio file metadata are - using mutagenesis

How to solve the problem of inaccessibility after Tomcat deploys war package How to solve the problem of inaccessibility after Tomcat deploys war package Jan 13, 2024 pm 12:07 PM

How to solve the problem that Tomcat cannot successfully access the war package after deploying it requires specific code examples. As a widely used Java Web server, Tomcat allows developers to package their own developed Web applications into war files for deployment. However, sometimes we may encounter the problem of being unable to successfully access the war package after deploying it. This may be caused by incorrect configuration or other reasons. In this article, we'll provide some concrete code examples that address this dilemma. 1. Check Tomcat service

Use Python's __contains__() function to define the containment operation of an object Use Python's __contains__() function to define the containment operation of an object Aug 22, 2023 pm 04:23 PM

Use Python's __contains__() function to define the containment operation of an object. Python is a concise and powerful programming language that provides many powerful features to handle various types of data. One of them is to implement the containment operation of objects by defining the __contains__() function. This article will introduce how to use the __contains__() function to define the containment operation of an object, and give some sample code. The __contains__() function is Pytho

How to convert MySQL query result array to object? How to convert MySQL query result array to object? Apr 29, 2024 pm 01:09 PM

Here's how to convert a MySQL query result array into an object: Create an empty object array. Loop through the resulting array and create a new object for each row. Use a foreach loop to assign the key-value pairs of each row to the corresponding properties of the new object. Adds a new object to the object array. Close the database connection.

How to solve external resource access and calls in PHP development How to solve external resource access and calls in PHP development Oct 08, 2023 am 11:01 AM

How to solve the problem of accessing and calling external resources in PHP development requires specific code examples. In PHP development, we often encounter situations where we need to access and call external resources, such as API interfaces, third-party libraries or other server resources. When dealing with these external resources, we need to consider how to access and call safely while ensuring performance and reliability. This article describes several common solutions and provides corresponding code examples. 1. Use the curl library to call external resources. Curl is a very powerful open source library.

See all articles