Java Learning Record notes--inheritance, Super,object class

Source: Internet
Author: User

Inherited:

Inheritance in Java is single-inheritance.


1. Subclasses have all the properties and methods of the parent class.

However, property and method modifiers cannot make private.

2. The ability to reuse the code of the parent class.

The override of the method needs to satisfy the condition:

A. Return value type
B. Method name
c. Type and number of parameters
Must be exactly the same as the parent class.

Initialization Order of Inheritance:

1. Initialize the parent class and then initialize the subclass
2. Run the Initialize object property before running the initialization in the constructor method.

Finalkeyword:

Final can modify classes, methods, properties, and variables.
Final decorated class , the class will be inherited differently.


Final modification Method , the method is overwritten (overridden) differently
Final modifier Properties
The property of the class is not implicitly initialized and cannot be initialized by itself (the initialization property of the class must have a value)
or assign a value in the constructor method (both can only be selected)
Final modified variable . The variable can only be assigned a single value, that is, a constant.

Superkeyword:

Used inside an object to represent the parent class object.


1. Access the properties of the parent class,
2. Access the methods of the parent class.

1. The construction of the subclass of the procedure in which the constructor of its parent class must be called.


2. Assume that the subclass is constructed in a method. The constructor method for calling the parent class is not displayed.
The system defaults to calling the parent class no-participate constructor.


3. Assume that the calling parent class construction method that is displayed must be placed in the first row of the constructor method.
4. Assume that the subclass constructor method does not show the constructor method that calls the parent class. There is no way to construct a parent class without a participation. Then compile Error!

Object class

The object class is the parent class for all classes.
1.toString () method.


The hash encoding of the object returned when defining the ToString () method inside the object class
(Object address String)
The ability to represent the properties of an object by overriding the ToString () method.

2.equals () method = = This is the case
The comparison is whether the object's reference points to the same memory address.

In normal cases, when comparing two objects, they are more equal than their values, so they are rewritten.

Java Learning Record notes-inheritance, Super,object class

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.