// JAVA TEST CODES: MY SECOND JAVA PROGRAM // These test codes will show how to inherit attributes and methods from a parent class // Here, I create a new class called Resident that inherits all properites and methods from Citizen class public class Resident extends Citizen { // I add a new attibute called city. Other attributes have already been inherited String city; // Here, I declare a constructor to initialize the class variables public Resident () { city = "Mandaluyong" ; } // Then I define one method to print one blank line and three lines of resident details public void displayResidentDetails () { System.out.println (); System.out.println ( "Resident Class"); System.out.println ( "Name of Resident = " + name); System.out.println ( "City of Resident = " + city); } /* This is the main method. Here, I create new object from Resident class. Then, I call the display method of this class after which I call the display method of the Citizen class. */ public static void main ( String args [] ) { Resident residentOying = new Resident () ; residentOying.displayResidentDetails () ; residentOying.displayCitizenDetails () ; } // And finally, our closing bracket. } /* Save this file as Resident.java in the same directory you saved the Citizen.java. Compile it using the command: javac Resident.java, then run it using the command: java Resident. You must have the Java Development Kit installed in your Windows computer to be able to compile and run java programs. You can download it from the Sun Microsystems web site or buy a Java book with included Cd-Rom. Run the archive file and accept all default answers during installation. Include the path of the JDK bin directory in your path environment using the msconfig command. Personalize the program using your own name, city, and nickname. E-mail me if you experience problems. */ /* Most of compilation errors wil be due wrong spelling or presence/absence of semicolons. */