Defining classes
The process of defining a class is the process of defining the properties of the class;
The property of a class is the short name of a tired static property, which refers to the data contained within the class.
The service of a class is called a member function or method.
Inherit extends
By defining an inheritance method, subclasses can get all the properties and methods of the parent class
Interface implements
Describes the functions and methods of which interface definitions are implemented in the current class
is a mechanism for implementing multiple inheritance in the Java language
The modifiers of the class are divided into:
Access control characters
Abstract class Descriptor
Final specifier
Properties of the class:
Describes the information inside a class, also known as a static property of a class
Class property is a simple variable
"Modifier" Variable type variable name "= Variable initial value"
Modifier Class Name Object name "=new class name (actual argument list)"
If you use an object from another class as a property of the class defined by the current class,
To ensure that the class in which the object resides is in the current class that can already be referenced by the current class
Modifiers for class properties include:
Access control characters
static modifier statics
Final modifier final
volatile modifier volatile
Master Transient of transition lost
Method of the Class (member function)
Used to specify actions on class properties
Mechanisms for implementing the internal functions of a class
is also a window of class interacting with the outside world
Syntax for declaring a method:
"Modifier" returns a value type method name (parameter list)
Trows Exception name 1, exception name 2, ...
{
Method Body:
local variable declaration;
Statement sequence;
}
The modifiers of the method include:
Access control characters
static modifier statics
Abstraction Modifier Abstract
Final modifier final
Synchronization modifier Synchronous
Local modifier native
Constructors for classes
The Special place:
Constructor's method name is the same as the class name
Constructor has no return type
The main function of the constructor is to complete the initialization of the class object.
While creating a new object for a class, the system automatically calls the class's constructor to initialize the new object.
Java in declaring a class is, you can not define a constructor, the system will automatically generate a default constructor for the class
At this point the name of the constructor is the same as the class name, there are no formal parameters, and no action is done
Class has only one public access control
The access controls for properties and methods are:
Public
Private
Protected
Private protected
For classes in the same package, you can easily access and reference each other without any description
Classes in different packages can be accessed and referenced only if they are declared public, and then the import is declared on the program header.
The properties of Publici-decorated classes are called public properties
If the public property belongs to a public class, it can be used by all other classes
The public modifier causes security and data encapsulation to degrade, minimizing the use of the public attribute
The default access control specifies that the class can be accessed and referenced only by classes in the same package, not by classes in other packages, which are called packet-access.
Properties and methods within a class if there is no access control to qualify, it also means that they have package access and can be accessed and invoked by other classes in the same package
A property or method that is decorated with private can only be accessed and modified by the class itself, and cannot be obtained and referenced by any other class, including subclasses of that class.
Procted-Modified properties can be accessed by the class itself and the classes in the package
Public can be accessed arbitrarily
Static properties
Properties that are modified by static are called static properties
A static property is a common storage unit
Any object of a class that accesses it is the same value.
When an object of any class modifies it, the same memory unit is being manipulated.
Properties that are decorated by the static modifier are public properties that belong to the class
The static modifier modifies the method that belongs to the entire class
Methods that are not decorated with the static modifier are methods that belong to a specific object or instance
Declares that static of a method has at least a threefold meaning
When calling this method, the class name should be used as a prefix instead of a specific object name
A non-static method is a method that belongs to an object that has its own private code snippet in memory when the object's method is created
And the static method belongs to the whole class.
Its in-memory code snippet will be allocated and loaded as the class is defined, not by any object being proprietary
The static method can only handle data of the static type
Static initializers
Oil keyword static boot a pair of curly braces around a set of statements
The difference between a static initializer and a constructor:
Constructors are initialized for each newly created object, while static initializers initialize each class
The constructor is automatically executed by the system when a new object is generated with the operator, while the static initializer is run by the system call when the class to which it belongs is loaded into memory.
Unlike constructors, static initializers are not methods, there are no method names, return values, and argument lists
Abstract class
When a class is abstract by life, this class is called an abstract class
The so-called abstract class is the class with no concrete instance object
An abstract class is a collection of public properties of all its subclasses
One of the great advantages of using abstract classes is that you can use these public properties to improve the efficiency of your development and maintenance programs.
Final class, Final attribute, final method, Terminator
Final class
If a class is modified and qualified by the final modifier, it means that the class cannot have subclasses
Final attribute
Final is the modifier used to modify a constant, if the member variable of a class is declared final, then its value will not change during the execution of the program, that is, a constant
When specifying constants with the final modifier:
Data types that need to describe constants
You need to indicate the exact value of the constant
Because constant members of all classes ' objects have consistent values, constants are usually declared static in order to save space.
The class method that the final modifier modifies is the final method in which neither the function nor the inner statement can be changed, that is, a method that cannot be overloaded by subclasses of the current class
The final method fixed the specific operation, to prevent the subclass of the parent class of key methods of the redefinition of the error, to ensure the security and correctness of the program
All methods that have been qualified as private by the private modifier, and the methods contained in the final class, are considered final by default.
Terminator
Finalizers are methods that are executed when objects are reclaimed
protected void Finalize () {}
A finalizer is a method named Finalize that does not produce a list and return values
volatile modifier
The properties of a volatile class may be controlled and modified by several threads at the same time
Typically used to decorate properties that are subject to external input
Object-oriented properties of Java