Examples in java

Source: Internet
Author: User

Assume that Class B is A subclass or indirect subclass of Class A. When Class B is used to create an object and put the application of this object into the object of Class A, Class; a = new B (); or A a; B B = new B (); a = B; then, class A object a is the feature of the transformation object on the transformation object of the subclass object B. 1: The transformation object cannot operate on the member variables added to the subclass (this property is lost ), you cannot use the new method of subclass (some functions are lost). 2. The transformed object can operate member variables inherited or hidden by subclass, or use method 3 inherited or overwritten by subclass: when the method inherited or overwritten by the Operation subclass of the transformation object is to notify the corresponding subclass object to call these methods 4: The transformation object on the object can be forcibly converted to a child object, in this case, the subclass object has all the attributes and functions of the subclass. [html] class ape {private int n = 100; void crySpeak (String s) {System. out. println (s) ;}} class people Extends ape {void computer (int a, int B) // method added to the subclass. The transformation object cannot reference {int c = a * B; System. out. println (c);} void crySpeak (String s) {System. out. println ("**" + s + "**"); // subclass override parent class method} class example6 {public static void main (String args []) {ape monkey = new people (); // monkey is the transformation object monkey of the people object. crySpeak ("I love this game! "); People people1 = (people) monkey; // converts an on-transformation object to a subclass's people1.computer );}}

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.