/**
 * This class demonstrates using dynamic dispatch -- adding 
 * some comments to help you visualize how dynamic dispatch works.
 * 
 * Made the Parent and Child classes static and private to this class so that  
 * the variations of the dynamic dispatch example can exist in the same 
 * (default) package.
 *
 * @author Sara Sprenkle
 *
 */
public class VisualizingDynamicDispatchExample {  
    
    public static void main(String[] args) {
        Parent p = new Parent();
        Child c = new Child();
        
        p.method1();
        System.out.println("");

        c.method1();
        System.out.println("");
        
        p.method2();
        System.out.println("");

        c.method2();
        System.out.println("");
    }
    
    static private class Parent {
 
		public Parent() {
		}
		
		public void method1() {
			System.out.println("Parent: method1");   
		}
		
		public void method2() {
			System.out.println("Parent: method2");
			method1(); 
		}
		
	}
	
	static private class Child extends Parent {
	 
		public Child() {
		}
		
		@Override
		public void method1() {
			System.out.println("Child: method1");   
		}
		
		/*
		This method was *inherited* from the Parent class...
		public void method2() {
			System.out.println("Parent: method2");
			method1(); 
		}
		*/
		
	}

}
