1.20, create a parent class, create three methods in the parent class, override the third method in the subclass, create an object for the subclass, transform it upward to the base class, and call this method.

Source: Internet
Author: User

1  Public classPerson {2     3     //Method4     5      Public voidEat () {//define how to eat6         7System.out.println ("Defines the parent class person."));8     }9     Ten      Public voidWork () {//define how the parent class works One          ASystem.out.println ("Define the parent class person."); -     } -  the}
 Public classChildextendsperson{ Public voidWork () {//methods for defining sub-class workSystem.out.println ("Sub-class child does not love work"); }                     Public Static voidMain (string[] args) { person child=NewChild ();//Child class Person class, to upward transformationchild.work ();                Child.eat (); }

Subclass child does not love to work
Defines the parent class person. How to eat

1.20, create a parent class, create three methods in the parent class, override the third method in the subclass, create an object for the subclass, transform it upward to the base class, and call this method.

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.