JAVASE basic knowledge Note 7

Source: Internet
Author: User

Java SE Lesson 2
1. Polymorphism: A parent type reference can point to a child type object.
2. Parent p = new Child (); when calling a method using polymorphism, first check whether the Parent class has
The sing () method. If not, the compilation is incorrect. If yes, call the sing () method of the subclass.
3. There are two types of forced type conversion:
A) Up-to-type conversion (upcast): for example, to convert the Cat type to the Animal type, that is, to convert the child Type
Convert to the parent type. Explicit setting is not required for upward type conversion.
B) downcast: for example, converting the Animal type to the Cat type. Parent type
Convert to child type. For downward type conversion, it must be explicitly specified (mandatory type must be used)
Conversion ).
4. abstract class: the class modified by the abstract keyword is called an abstract class. Pumping
The object class cannot be instantiated, that is, the object (Instance) of an abstract class cannot be created ).
5. abstract method: The method modified by the abstract keyword is called the abstract side.
Method. Abstract methods must be defined in abstract classes. Compared with abstract methods, the previously defined method is
Make specific methods (with declarations and implementations ).
6. If a class contains an abstract method, the class must be an abstract class.
7. If a class is an abstract class, the class can contain specific methods (with declarations and implementations ).
8. If a class contains abstract methods, the class must be declared as abstract class.
That is to say, the class must be an abstract class; otherwise, if a class is an abstract class, the class can
Contains abstract methods or specific methods.
9. In any case, as long as a class is an abstract class, this class cannot be instantiated.
10. When the subclass inherits the parent class (the parent class is an abstract class), The subclass must implement the parent class.
All abstract methods defined in; otherwise, the subclass must be declared as an abstract class.
11. interface: the status of an interface is equivalent to that of a class. All methods in the interface are abstracted
Method. When declaring methods in an interface, you can use the abstract keyword or not. Connect
Abstract keywords are often omitted.
12. The interface can be considered as a special abstract class (the abstract class can have specific methods or abstract
Method, but the interface can only have abstract methods, but not specific methods ).
13. classes can implement interfaces. The implementation is represented by the keyword implements, representing the implementation of a class
An API.
14. If a class implements an interface, the class must implement all the methods declared in the interface. If
This class is an abstract class, so you do not need to implement methods in the interface.
15. Java is a single inheritance, that is, a class can only have one unique parent class; a class can implement multiple
Interfaces, separated by commas.
16. Polymorphism: the so-called polymorphism means that the reference of the parent type can point to the child type object or interface type.
Can point to the instance of the class that implements this interface. Strong Relationship between interfaces and classes implementing Interfaces
The conversion method is the same as that between the parent class and the subclass.
17. static Keyword: it can be used to modify attributes, methods, and
Class (subsequent courses)
18. static modifier attribute: no matter how many objects a class generates, all these objects use the unique
One static member variable. An object modifies the static member variable and other objects.
The value of this static member variable also changes. If a member variable is static
We can use the class name and member variable name (this method is recommended ).
19. static modification method: static modification method is called static method. For static methods, you can
Use the class name and method name for access.
20. Static methods can only be inherited and cannot be overwritten ).
21. final keywords: final can modify attributes, methods, and classes.
22. final modifier class: When a class is modified by final, it indicates that the class is a final class, that is, it cannot be
Inheritance.
23. final modification method: When a method is modified by final, it indicates that the method is an final state method,
That is, it cannot be overwritten ).
24. final: When an attribute is modified by final, it indicates that the attribute cannot be rewritten.
25. When final modifies a native data type, it indicates that the value of the native data type cannot change.
(For example, it cannot be changed from 10 to 20). If final modifies a reference type, it indicates the reference.
The type cannot point to another object, but the content of the object to which the reference points can change.
.
26. For final type member variables, there are generally two initial value assignment methods:
A) Assign the initial value when declaring the final type member variable.
B) the initial value is not assigned when the final type member variable is declared, but is assigned to all the class constructor methods.
Upper initial value.
27. static code block: static code block. Static code blocks also perform initialization. First
First, execute the static code block, and then execute the constructor. The static code block is executed when the class is loaded,
The constructor is executed when an object is generated. To call a class to generate an object, you must first
To load the class to a Java Virtual Machine (JVM), then the JVM loads the class to generate the object.
28. The static code block of the class is executed only once. It is executed when the class is loaded, because each class only
It will be loaded once, so the static code block will only be executed once. The constructor is not
The constructor of the class is called when an object is created.
Method once.
29. If there are both constructor methods and static code blocks in the inheritance system, first execute the top-level class
The static code block is always executed to the static code block of the lowest-level class, and then the top-level class is executed.
The constructor is always executed to the constructor of the underlying class. Note: static code blocks only run
Once.
30. You cannot access non-static member variables in static methods. You can access static members in static methods.
Variable. You can access static member variables in non-static methods.
31. Conclusion: static users can only access static users. Non-static users can access everything.
32. this keyword cannot be used in static methods.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.