Java Beginner Notes Summary Day8

Source: Internet
Author: User
Tags java reference

Final keyword: end-of- word

Constants: Define once, assign a value once
Variables: Defined once, assigned multiple times

Types of constants
1) Basic type: The value stored by the constant itself (business data) cannot be changed
2) Reference type: The value stored by the constant itself (the address of the object) cannot be changed, and the contents of the object can be changed.
A) modifier variable---"constant
1) Local constants
Method parameter (local constant): cannot be assigned to a method because it has been assigned when called.
2) Member constants
Without a default value, you must create an object to ensure that all member constants have default values
A) define and assign B) construct block C) constructor
3) Static constants
Without a default value, you must load the class to ensure that all static constants have default values
A) Definition and assignment c) static block

b) Modification method
Role: Prevent the parent class from being overridden by a quilt class
c) Modified class
Role: Prevent classes from being inherited

Object Common overriding method
A) ToString: Converts the current object to a string
tostring-string format for obj: Full class name [email protected]+hashcode16 binary form
Typically the string does not satisfy the requirement-the content of the object cannot be explicitly represented = = "needs to be rewritten
Specifically, those member variables that represent the object---"Requirements
b) Hashcode: Converts the current object to an integer
Spec: If the "content is the same" for two objects, they will generate the same integer
Obj's hashcode "content is the same" refers to the same address, whose integers are generated by the object address.
Business "content is the same" is usually determined by the object member variables, so--"need to rewrite
Depending on the object's member variables to determine the "content of the same"---"Demand decision

c) equals: Compares the current object to another object, returns True if the content is the same, or false
"Content is the same" for the Equals of obj: The address of the object is compared
Need to rewrite!!

Hashcode and equals are all judged by the same object content!!!
Then we need to rewrite it at the same time

Type conversions for reference types

A) automatic type conversion
Super-type reference variable = subtype value;

b) Coercion type conversion
Subtype Reference variable = (subtype) The value of the super-type;

Watch out.
1) type of conversion to be successful, then one type of value (object type) must be "yes" another type
2) Coercion type conversion: there must be a relationship between two types (inheritance, implementation)--"otherwise the compilation will not pass
3) In the run time if the type can not be converted--error--"classcastexception
4) instanceof keyword--"Check whether the type can be converted directly

Polymorphic-for Hyper-type programming

Grammar:
1) A super-type reference to an object of subtype
2) subtypes override method for super-type
3) Super-type reference calling subtype override method

3) Super-type reference calling subtype override method
The overridden method of the parent class can be accessed in the subtype, and also has access to its own override method
--"How to call?"
Java Reference calling method
A) compile see-"reference type"
b) Run see-"Object type

For Hyper-type programming
1) Define a super-type---for multiple concrete classes to accept objects of each specific class
2) Define a unified function for a specific class in a super-type
3) Call unified functionality with polymorphic Hyper-type references


Super keyword

Super and this comparison
1) Super and this point object--"current object
2) Super and this call resources (properties and methods), the lookup process is different
A) Super from the parent class of the current class to the inheritance chain to find corresponding (properties and methods), to find the call
b) This from the current class to the inheritance chain to find the corresponding (properties and methods), to find the call

The role of Super
1) Calling the parent class (inheritance chain) overridden method
2) Call the parent class (inheritance chain) with the name of the attribute (basic not used)
3) Super ([constructor parameter of parent class])---Call the specified constructor of the parent class
Grammar:
1) must be in the constructor
2) must be the first line of code

This ([constructor parameter for current class])---"calls its own specified constructor
Grammar:
1) must be in the constructor
2) must be the first line of code
Watch out.
1) Super () and this () must be the first sentence, so you cannot use both
2) Subclass Constructor if the write super ([constructor parameter] of the parent class) is not displayed, then by default join Super (), call the parent class null constructor

Java Beginner Notes Summary Day8

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.