JAVA Inheritance extends

Source: Internet
Author: User

/*inherit 1, improve the reusability of code, simplify the code 2, let the class and the class has an inheritance relationship, only the existence of the characteristics of the later polymorphism note: Do not want to get other classes to simplify the code, and to establish an inheritance relationship, you must have the class and the class has an inheritance relationship, inheritance relationship: is a ( If something is a kind of something, for example, a cat is a cat family. 3, the subclass has a member of the parent class 4, the subclass can not have the parent class in the private decorated member 5, Java support multi-layered inheritance in multi-layer inheritance in the hierarchy of the sub-class has the entire inheritance system members, The top-level parent class defines the generality of all subclasses. Java does not support multiple inheritance, only support single inheritance, because multiple inheritance is a security hazard (this multi-inheritance is not a multi-layered inheritance, but a class does not support inheriting multiple classes) when more than one parent class defines the same member, the subclass object is not sure which one to run. Java preserves this mechanism and uses it in another way (multiple implementations)*///Parent class, Super class, base classclassporson{String name; intAge ;}//sub-classclassStudentextendsporson{voidStuby () {System.out.println (Learning); }}//sub-classclassTeatherextendsporson{voidTeath () {System.out.println (Teaching); }} Public classtest{ Public Static voidMain (string[] args) {}}/*English extension: Porson: Man student: Student Teather: Teacher*/

JAVA Inheritance extends

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.