. 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