Older Dick Silk Self-study note--java 0 basics to rookie--018

Source: Internet
Author: User

Final, polymorphic

1. Final

Final: Constant, cannot be modified. Classes can be decorated (cannot be inherited), methods (cannot be overridden), variables (can only be assigned once).

Caveats: Final decorated base type, the value of the base type cannot be changed.

The final decorated reference type, the address of the reference type cannot be changed, and the value in the object heap can be changed.

Final static constants are best assigned when declared, and non-static constants are best assigned before the end of the constructor.

2. polymorphic

Polymorphism: A thing that states in different timetables, such as: Cat is Cat "cat c=new Cat ();", Cat is Animal "Animal c=new Cat ();".

The precondition of polymorphism: there is inheritance, there is a method of rewriting, there is a parent class reference subclass.

The advantages of polymorphism: It improves the maintainability and extensibility of the code.

The disadvantage of polymorphism: The parent class cannot access the features that are unique to subclasses (can be accessed through strong transfers, such as: Father f=new Son (); Son s= (son) F; ) 。

Note: Subclasses can access the contents of the parent class, and the parent class cannot access the contents of the child class.

When the parent class is the new subclass, access the constructor of the parent class.

When the parent class is new, the static method compiles and runs the contents of the parent class (because the static method is only related to the class).

When the parent class is new, the member variable, the member method compiles the contents of the parent class, the member variable runs the contents of the parent class, and the member method runs the contents of the subclass.

Older Dick Silk Self-study note--java 0 basics to rookie--018

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.