/************************************************* Author : Michael Robinson Program : multiClasses.java Purpose : This project will cover the following: Interfaces Classes inside classes. Polymorphism More Inheritance Abstract classes Abstract methods This project does the following: 1 - Create an Interface named customerInterface 2 - Create a class called superCustomer to implement the customerInterface. This class will also be a Super-class. 3 - Create two subclasses named wholesaleCustomer and retailCustomer both inheriting from superCustomer Updated : September 9th, 2099 ****************************************************************/ public class multiClasses { //class abstractClass.java inside multiClasses.java class /*********************************************************** Author : Michael Robinson Program : abstractClass.java Purpose : this is an abstract class, it can contain as many abstract methods as needed. Abstract classes can also contain as many regular methods as needed. Updated : September 9th, 2099 ***********************************************************/ //this is an abstract class abstract public static class abstractClass { //this is an abstract method NO BODY NEEDED abstract void hello(); public static void methodOne() { System.out.println( "I am methodOne, a regular method " + "inside the abstractClass" ); }//end public static void methodOne() public static void methodTwo() { System.out.println( "I am methodTwo, a regular method " + "inside an the abstractClass" ); }//end public static void methodTwo() }//end abstract public class abstractClass /*************************************************************** Author : Michael Robinson Program : extendsAbstractClass.java Purpose : This class extends the abstract class named abstractClass, It overrides the abstract hello method in the abstract class. Updated : September 9th, 2099 ***************************************************************/ public static class extendsAbstractClass extends abstractClass { //this method is an abstract method implementation public void hello() { System.out.println( "I am the implementation of the " + "hello abstract method,\n" + " inside the extendsAbstractClass.java" ); }//end public void hello() public static void methodOne() { System.out.println( "I am methodOne inside the " + "extendsAbstractClass.java." ); }//end public static void methodOne()\n public static void methodTwo() { System.out.println( "I am methodTwo inside the " + "extendsAbstractClass.java." ); }//end public static void methodOne() }//end public class extendsAbstractClass extends abstractClass public static void usingAbstractClass() { System.out.println( "This section will use ABSTRACTION " + "and inheritance.\nThere is an abstract class called " + "abstractClass\nwith one abstract method called " + "abstractClass\n hello and two\nlocal methods called " + "methodOne and methodTwo\nThe abstract hello method " + "will be implemented\nand the other two methods will " + "be overridden\nby a class called extendsAbstract.\n" ); //use a regular method in the abstract class abstractClass.methodOne(); abstractClass.methodTwo(); System.out.println( "\nNow I will create an " + "extendsAbstractClass object\n" ); //create an object of a class that //inherits an abstract class extendsAbstractClass one = new extendsAbstractClass(); //use a method from this new method one.hello(); //use an overridden regular method //in the extendsAbstractClass extendsAbstractClass.methodOne(); extendsAbstractClass.methodTwo(); System.out.println(); }//end public static void main( String arg[] ) public static void polyMethod( superCustomer obj ) { System.out.print( "Hi I am the " + obj.getCustomerType() ); System.out.print( ", my name is " + obj.getCustomerName() ); System.out.println( ". These are my data fields:" ); }//end public static void polyMethod( superCustomer obj ) public static void usingInterface() { //Polymorphism: Creating object rCust of retailCustomer() //sub-class with super-class superCustomer() data type superCustomer rCust = new retailCustomer(); System.out.println( "Using an object of retailCustomer " + "class and superCustomer data type" ); //accessing methods in rCust sub-class polyMethod( rCust ); //getting data from rCust sub-class object String theArray[] = rCust.getCustomerData(); for( String temp : theArray ) { System.out.print( temp + " " ); } System.out.println( "\n\nNow I will use arrays containing " + "sub-classes" ); //creating an array of superCustomer data type superCustomer array[] = new superCustomer[2]; //loading array[0] with object of retailCustomer sub-class array[0] = new retailCustomer(); //loading array[1] with object of wholesaleCustomer sub-class array[1] = new wholesaleCustomer(); //processing the sub-classes for( superCustomer arrayIndex : array ) { polyMethod( arrayIndex ); for( String inner : arrayIndex.getCustomerData() ) { System.out.print( inner + " " ); } System.out.println( "\n" ); }//for( superCustomer temp : array ) System.out.println( "End of Polymorphism examples\n\n" ); }//end public static void usingInterface() public static void main( String arg[] ) throws InterruptedException { usingInterface(); usingAbstractClass(); }//end public static void main( String arg[] ) // throws InterruptedException }//end public class multiClasses