Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the set Analysis of java knowledge points

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to understand the collective analysis of java knowledge points. Many people may not understand it very well. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

1. Initialization of object

(1) initialization of non-static objects

When you create an object, all data members of the class in which the object resides are initialized first.

Basic type: int type, initialized to 0. 0.

If it is an object: these objects are initialized sequentially.

Until all class members have been initialized, the constructor of this class is called to create the object.

The function of the constructor is to initialize.

(2) initialization of static objects

The static variable of the main class in the program is initialized before the main method executes.

Not only do all static variables in the class initialize when the object is first created, but also access a

Class (note that no such object is created at this time), all static variables are also specified in the class

Initialize the sequence in the.

2. when inheriting, the initialization process of the object

(1) the superclass of the main class initializes static members sequentially from high to low, regardless of whether the static members are private or not.

(2) initialization of static members of the main class.

(3) the superclass of the main class invokes the default constructor from high to low. Note that after calling each

Initialize the non-static object of the superclass before the default constructor of the superclass.

(4) initialization of non-static members of the main class.

(5) call the constructor of the main class.

3. About the construction method

(1) A class can have no constructor, but if there are multiple constructors, there should be a default constructor.

Method, otherwise, when inheriting this class, you need to explicitly call some non-default construct of the parent class in the subclass

There's a way.

(2) in a constructor, other constructors can only be called once, and the constructor can be called.

Method must be the first statement.

4. About public, private and protected

(1) A class without public modification can be accessed by other classes under the following conditions: a. The two classes are in the same text

In the piece, b. Two classes are in the same folder, c. The two classes are in the same package.

(2) protected: inherited classes and classes of the same package can be accessed.

(3) if the constructor is private, then objects of this class cannot be created in other classes.

5. Abstract class

(1) Abstract classes cannot create objects.

(2) if a method in a class is an abstract method, the class must be an abstract abstract class.

(3) classes that inherit abstract classes must implement abstract methods in abstract classes.

(4) there can be abstract methods or non-abstract methods in abstract classes. Abstract method cannot be private.

(5) the class that inherits the abstract class indirectly can not give the definition of abstract method.

6. Final keyword

(1) just because an object is a constant does not mean that its members can still operate if it cannot be transformed.

Do it.

(2) the constant must be assigned before it is used, but it can only be initialized at the same time as the declaration.

Initialization in the creation method.

(3) final-modified methods cannot be reset (methods with the same name cannot appear in subclasses).

(4) if a class is declared as final, all methods are final, whether or not they are

Final decoration, but the data member may or may not be final.

7. Interface interface (using implements to implement the interface)

(1) all data in the API are static and final, that is, static constants. Although we don't need this.

Two keywords are modified, but the constant must be assigned an initial value.

(2) the methods in the interface are all public. In the implementation interface class, the implementation method must be public.

Keyword.

(3) if public is used to decorate the interface, the interface must be the same as the file name.

8. Multiple inheritance

(1) if a class inherits a class and interface, then the class must be written before and the interface after.

Interfaces are separated by commas.

(2) there can be multiple inheritance between interfaces, so pay attention to using the keyword extends.

(3) although a class implements only one interface, it not only implements all the methods of this interface, but also

To implement the methods of the interface that this interface inherits, all methods in the interface must be implemented in the class.

9. Interface embedding

(1) the interface is embedded in the class and can be decorated with private. At this point, the interface can only be in the class in which it is located

Other classes cannot be accessed.

(2) the interface embedded in the interface must be public.

10. Embedding of classes

(1) A class can be embedded in another class, but not in an interface.

(2) in static methods or other methods, inner class objects cannot be created directly, but by means.

Get it.

There are two ways:

Class A {class B {} B getB () {B b = new B (); return b;}

} static void m () {An a = new A (); A.B ab = a.getB (); / / or

It is A.B ab = a.new B ();}

(3) one class inherits the inner class of another class, because the superclass is the inner class, and the construction of the inner class

The builder cannot be called automatically, so the construction of the superclass needs to be explicitly called in the constructor of the subclass.

Method. Follow the example above:

Class C extends A.B {C () {new A (). Super (); / / this sentence is

The call to the inner class constructor is realized. }}

The constructor can also be written as follows:

C (An a) {a.super ();} / / use this constructor to create an object, which is written as C

C = new C (a); an is the object of A.

11. Exception class

Except for the RunTimeException class, all exceptions in JAVA must be caught or thrown.

After reading the above, do you have any further understanding of how to understand the collective analysis of java knowledge points? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report