Java Essential Basics (2)

Source: Internet
Author: User

1. polymorphic: A reference to a parent type can point to an object of a subtype.
2.Parent P = new Child (); When calling a method using polymorphic mode, first check if there is a sing () method in the parent class, if there is no compile error;Sing ()Method. 3. There are two types of coercion type conversions: a) Up-type conversions (upcast): For example, converting a Cat type to a Animal type, going to a subtype
Convert to a parent type. For up-type conversions, you do not need to specify explicitly. b) down type conversion (downcast): For example, convert the Animal type to Cat type. Upcoming Parent Type
Converted to subtypes. For down-type conversions, you must explicitly specify (you must use the mandatory type
Conversion). 4. Abstract class: Classes that are decorated with the abstract keyword are called abstract classes. Smoke
The elephant class cannot be instantiated, that is, an object (instance) of an abstract class cannot be new. 5. Abstract method: Methods that are decorated with the abstract keyword are called abstract parties
Method. Abstract methods need to be defined in an abstract class. As opposed to an abstract method, the previously defined method is called
Do a specific method (there are declarations, there are implementations). 6. If a class contains an abstract method, then the class must be an abstract class. 7. If a class is an abstract class, the class can contain concrete methods (declarations, implementations). 8. If a class contains an abstract method, the class must be declared as an abstract class, or
That is, the class must be an abstract class, and conversely, if a class is an abstract class, the class can
Contains an abstract method, or it can contain specific methods. 9. In either case, if a class is an abstract class, the class cannot be instantiated. 10. In the case where the subclass inherits the parent class (the parent class is an abstract class), then the subclass must implement the parent class
Otherwise, the subclass needs to be declared as an abstract class. 11. Interface (interface): The status of the interface is equivalent to class, and all the methods in the interface are abstract parties
Method. When you declare a method in an interface, you can use the abstract keyword or you can not use it. Wildcard
Typically, the abstract keyword is omitted. 12. Interfaces can be thought of as special abstract classes (abstract classes can have specific methods, or they can have abstract
method, and there can be only abstract methods in the interface, and there can be no specific method. 13. Classes can implement interfaces. The implementation uses the keyword implements representation, which represents a class that implements the
An interface. 14. When a class implements an interface, the class must implement all the methods declared in the interface. If
The class is an abstract class, so there is no need to implement the methods in the interface. Java is single-inheritance, which means that a class can have only one parent class, and a class may implement multiple
interface, separated by commas between multiple interfaces. 16. Polymorphism: A so-called polymorphic, that is, a reference to a parent type can point to a subtype of an object, or an interface type
Reference can point to an instance of the class that implements the interface. About the strong between the interface and the class that implements the interface
The type conversion method is exactly the same as the coercion type conversion between the parent class and the child class. The Static keyword: can be used to modify properties, can also be used for cosmetic methods, and can also be used to decorate
Class (in the course of the following lecture) 18. Static Modifier property: Regardless of how many objects a class generates, all of these objects work together using the
One by one parts static member variable; An object modifies the static member variable, and the other object
The value of the static member variable will change as well. If a member variable is static,
Then we can use the class name.The name of the member variable to use it (recommended in this way). The static Modification method: The method of static modification is called a statics method. For static methods, you can
Using the class name.Method name to access it in the same way.
.Static methods can only inherit and cannot be overridden (Override)。 Final keyword: Final can modify properties, methods, classes. Final Modified class: When a class is modified by final, it means that the class is a final state class, which cannot be
Inherited. Final modification method: When a method is modified by final, it indicates that the method is a final state method,
That cannot be overridden (override). Final Modified properties: Indicates that the property cannot be overwritten when a property is modified by final.
.WhenFinalWhen a native data type is decorated, the value representing the native data type cannot be changed
(e.g. not fromTenInto -); ifFinalWhen a reference type is decorated, the reference is represented
The type can no longer point to another object, but the contents of the object that the reference points to are subject to change
Of 26. For final type member variables, there are generally two ways to assign the initial value: a) When declaring a member variable of the final type, assign the initial value B) without assigning an initial value when declaring a member variable of the final type, but in all the constructor methods of the class
The initial value. The static block of code. The function of static code blocks is also to do some initialization work. First
Execute the static code block first, and then execute the construction method. Static code blocks are executed when the class is loaded,
The construction method is executed when the object is generated, and to invoke a class to generate the object, you first need to
To load a class onto a Java virtual machine (JVM), then the JVM loads the class to generate the object. 28. The static block of code for a class executes only once, when the class is loaded, because each class only
will be loaded once, so the static code block will only be executed once, and the construction method is not
The constructor of the class is called when the secondary becomes an object, so the new one invokes the construct
Method once. 29. If there are both constructor methods and static code blocks in the inheritance system, first the topmost class is executed
Static block of code that executes to the static code block of the lowest class and then executes the topmost class
Construction method, which is implemented to the bottom class. Note: Static code blocks will only perform
A. 30. Non-static member variables cannot be accessed in static methods; static members can be accessed in static methods
Variable. Static member variables can be accessed in non-static methods.
.Summary: Static can only access static, non-static access to everything. 32. Cannot be used in static methods ThisKey word.

Java Essential Basics (2)

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.