Inherit 3-a B E

Source: Internet
Author: User

. Write a Java application that consists of 3 classes: class a ,classB , and main class E . Which

Class B is a subclass of class A , new member variables and member methods are added to subclass B , and the parent class is hidden

A member variable and overrides a member method of parent Class A. In main class E , in the main method, create class B

object and assign it to the object A of the parent class A , use the On Transformation object a to test some of the features of the object being transformed.

1  PackageMianxiangduixiang;2 3  Public classJichenga {4     PrivateString food;5      PublicString Getfood () {6         returnFood ;7     }8      Public voidSetfood (String food) {9Food =Food ;Ten     } One       Public voidSpeakfood () A      { -System.out.println ("Go out to dinners"); -      } the       Public voidAmericanfood () -      { -System.out.println ("Steak, pizza, hamburger"); -      } +      Public Static voidMain (string[] args) { -         //TODO Auto-generated method stubs +      A     } at  -}

1  PackageMianxiangduixiang;2 3  Public classJichengbextendsJichenga {4 5      Public voidSpeakfood ()6     {7SYSTEM.OUT.PRINTLN ("Pass the Board");8     }9      Public voidChinafood ()Ten     { OneSystem.out.println ("Shandong cuisine, Sichuan, Cantonese, Fujian, Su, Zhe, Hunan, Hui cuisine")); A     } -      Public Static voidMain (string[] args) { -         //TODO Auto-generated method stubs theJICHENGB a=Newjichengb (); -A.setfood ("Eight major cuisines"); - A.speakfood (); - A.americanfood (); + A.chinafood (); -     } +  A}

Inherit 3-a B E

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.