1 class basetest 2 {3 //Parent class Variable4 PrivateString baseName = "base";5 //parent class static variable6 Public StaticString Staticfield = "Parent class static variable";7 //Parent class static methods8 Public Static voidOrder ()9 {TenSystem.out.println ("Parent class static Method-"); OneSystem.out.println ("Staticfield:" +Staticfield); A } - //parent class static initial code block - Static the { -System.out.println ("Parent class static initialization code block-"); -System.out.println ("Staticfield:" +Staticfield); - } + //initializing a block of code - { +System.out.println ("Parent class non-static initialization code block-"); ASystem.out.println ("BaseName:" +baseName); at } - //constructor Function - Publicbasetest () - { -System.out.println ("Parent class constructor method"); - callname (); in } - //member Methods to Public voidcallname () + { -System.out.println ("Parent class Callname Method-"); theSystem.out.println ("BaseName:" +baseName); * } $ }Panax Notoginseng - the Public class Zhuchenxu extends basetest + { A the //main program class variables + PrivateString zhuchenxuname = "Zhuchenxu"; - //main program class static variable $ Private StaticString Zhuchenxufield = "Main program class static variable"; $ //main Program class static method - Public Static voidOrder () - { theSystem.out.println ("Main program class static Method-"); -System.out.println ("Zhuchenxufield:" +Zhuchenxufield);Wuyi } the //Main program class static initial code block - Static Wu { -System.out.println ("Main program class static initialization code block-"); AboutSystem.out.println ("Zhuchenxufield:" +Zhuchenxufield); $ } - //initializing a block of code - { -System.out.println ("Main program class non-static initialization code block-"); ASystem.out.println ("Zhuchenxuname:" +zhuchenxuname); + } the //constructor Function - PublicZhuchenxu () $ { theSystem.out.println ("Main Program class construction method"); the callname (); the } the //member Methods - Public voidcallname () in { theSystem.out.println ("Main program class Callname method-"); theSystem.out.println ("Zhuchenxuname:" +zhuchenxuname); About } the the the + Public Static voidMain (string[] args) - the {BayiSYSTEM.OUT.PRINTLN ("-----[[-------"); the Zhuchenxu s = new Zhuchenxu (); the basetest m = s; - -SYSTEM.OUT.PRINTLN ("-----[[-------"); the the the } the}
The results of the operation are as follows:
Super class, subclass, main program Execution Ultimate Step (ii)