Java grammar rules

xiaoxiao2021-03-06  40

// Polymorphism

Definition: means a polymorphic reference can point to the listed listed

Java rewrites and method overloads to achieve polymorphism

// extends

Create a subclass of a class by adding an Extends clause in a class declaration.

Subclasses can inherit the members variables and methods for the PUBLIC, Protected, Friendly, but cannot inherit the member variables and methods of access.

// final class

Final class cannot be inherited

If you think a definition of a class is perfect, you don't need to regenerate it into its subclasses. At this time, it should also be modified as Final class.

Final Class ClassName {...}

// Abstract class

The Abstract class must be inherited and the method must be overloaded.

It should not be subjected to an object.

Number is an Abstract class

//java.lang.Object class

1.equals (): Compare status and functionality

Integer One = New Integer (1), Anotherone = New Integer (1);

IF (one.equal (annotherone)) {

System.Pringln ("Objects Are Equal");} // Return True

2.getclass ()

Is Final method,

Void PrintClassName (Object Obj)

{

System.out.println ("The Object's Class IS

" obj.getClass (). getname ();

}

Create an instance of a class, the object created can be any class

Object CreateNewsTanceOf (Object Obj)

{

Retuen obj.getClass (). newinstance ();

}

3.Tostring ()

Returns the string of the object

System.out.println (thread.currentthread (). TOSTRING ());

4.Finalize ();

5.Notify (), NotifyAll (), Wait () is used in multi-threaded synchronization

//Member variables

. STATIC: Class variable

. Final: constant

. Volatile: shared variable

// member method

. Static: You don't need to use (class members), others are (instance members)

. Abstract and Final, whether it is overloaded (can be and not)

. Native: Integrate the Java code and other languages

. Synchronized: Controls multiple concurrent threads to shared data

. ThrowSexceptionList: Lead-processed

. This: Reference current object

. Super: Quote the parent class of the current object

Use:

(1) Super.variable // Use to access the parent class hidden member variables

(2) Super.Method ([paramlist]) // Used to call the method of being overloaded in the parent class

(3) Super. ([Paramlist]) // Call the constructor in the parent class

In the class method (static), this or super modifier cannot be used

// interface

Is a collection of method definitions and constant values

. The same behavior of the irrelevant class can be achieved by the interface without considering the hierarchical relationship between these classes.

. The method of multiple classes need to be implemented by an interface can be indicated.

. You can understand the interactive interface of the object by an interface without having to understand the class corresponding to the object.

Java does not support multiple inheritance (a class can be a subclass of multiple classes), and its multiple inheritage is implemented with an interface.

In the statement of the class, use IMPLEMENTS to represent a class to use an interface, which can use the constant defined in the interface, and all methods defined in the interface must be implemented. A class can implement multiple interfaces, with separate

转载请注明原文地址:https://www.9cbs.com/read-53699.html

New Post(0)