Java Study Notes (Sun Xin tutorial) 2

Source: Internet
Author: User
. Constructor
If the class you write does not provide a constructor, Java compilation automatically provides a default constructor for your class and provides default values for various fields of your class.
Various default values:
Numeric Type 0
Boolean false
Char '\ 0'
Object null
Name
Field: The field is the various variables and constants you define in the class.
Attribute: attribute is the method used to operate this class.
2. Method overload)
Condition for overloading: A method can be overloaded only when the method name is the same but the parameter type or number of parameters are different.
3. All class instances Share methods, but do not share fields.
That is to say, the member methods called by all instances (that is, objects) of a class have only one copy in the memory, although there may be multiple objects in the memory, the data member has a copy in each object of the class (in other words, each has its own copy. This copy refers to the class) whenever an instance method is called, this variable is set to a specific class object that references the method of the instance. Method Code Then it is associated with the specific data of the object represented by this.
4. Final variable Declaration
1. As a convention, constants are usually defined in uppercase.
2. To save memory, we usually declare constants as static
The final variable must be assigned a value when it is declared, or assigned by the constructor.
Why does he want to do this? Why cannot he do this and learn it with an attitude of knowledge? Program Design.
5. Override)
Define a method in the subclass that has the same name as the parent class, and has the same return type and parameter type. It is called method overwrite.
Overwrite occurs between the subclass and parent class.
6. the constructor of each subclass implicitly calls the constructor of the base class, and is in the first line of the constructor of the subclass. If this constructor does not exist in the parent class, the solution is to explicitly call the constructor of the parent class in the subclass.
7. Polymorphism
When a subclass is assigned to its parent class, when the method of this class is called, if the subclass has one, the method of the parent class is called first. When the subclass does not have one, the method of the parent class is called.

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.