Summary of characteristics of Java polymorphic members

Source: Internet
Author: User

1: Member variables, compile-time: Refer to the class in which the reference variable belongs to has the member variable called, has, compiles through, no, compiles failed.

Run-time: production test whether the referenced variable belongs to a class that has a calling member variable and runs the member variable in the owning class.

(Simple: Compile and run-time reference to the left of the equals sign)

2: Member functions compile-time: Refer to the class in which the referenced variable belongs to have the function called, have, compile through, no, compile failed.

Runtime: Refer to whether the object belongs to a class that has a function called, there, compile through, no, compile failed.

(Simply put: look to the left at compile time, see right at runtime)

3: Static functions, compile time: Refer to the class in which the reference variable belongs has a static method called, there, compile through, no, compile failed.

Runtime: Refer to the class in which the reference variable belongs has a static method called, there, compile through, no, compile failed.

(Simple: Compile and run look to the left) "static method can be called directly with the class name."

1 Importjava.util.ArrayList;2 ImportJava.util.Iterator;3 Importjava.util.List;4 5  Public classTest {6 7      Public Static voidMain (string[] args) {8         //TODO auto-generated Method Stub9A A =NewB ();TenA.dosomething ();//wo shi A OneA.B ();//hi:b ASystem.out.println (A.AA);//8 -  -     } the  - } -  - classA { +     intAA = 8; -  +      PublicA () { ASystem.out.println ("A"); at     } -  -      Public Static voiddosomething () { -System.out.println ("Wo shi A"); -     } -  in      Public voidB () { -System.out.println ("Hi:a"); to     } +  - } the  * classBextendsA { $     intAA = 10;Panax Notoginseng  -      PublicB () { theSystem.out.println ("B"); +     } A  the      Public Static voiddosomething () { +System.out.println ("Wo shi B"); -     } $  $      Public voidB () { -System.out.println ("Hi:b"); -     } the  -}
3 Examples of features

The result is:

A
B
Wo Shi A
Hi:b
8

Summary of characteristics of Java polymorphic members

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.