class Dogs {

    static int numDogsInGodsWorld;

    String color;

    static int getNumberOfDogsInGodsWorld() 
                     { return numDogsInGodsWorld; }

    String getColor() { return color; }

    void stroke() { System.out.println("."); }

    // Signatur: (a) Methodenname
    //           (b) Anzahl/Liste der Parameter - Typen
    void stroke(int howOften) {

	for (int i=0; i < howOften; i++ )
	    stroke();

    }


    Dogs(String c) { color = c; numDogsInGodsWorld++; }

}




class NiceDogs extends Dogs {

    int x;

    NiceDogs(String c) { super(c); }


    void stroke() {
	System.out.println("woof! - wag tail!!!");
    }


}

class BadDogs  extends Dogs {

    BadDogs(String c) { super(c); }


    void stroke() {
	System.out.println("bark and growl!!! - gnash teeth!"+
                           " Go for the throat!");
    }


}


public class WorldOfDogs {

    public static void main(String[] args) {

	System.out.println("At start: numDogsInGodsWorld = " 
                            + Dogs.numDogsInGodsWorld);

	System.out.println("And our Lord sayeth:" +
                     " There shall be a nice brown doggy");

        // <Klasse> <Variablenname> = new <Konstruktor>(...)
	NiceDogs doggy1 = new NiceDogs("brown");

	System.out.print("Stroking the nice dog with color " 
                           + doggy1.getColor() + 
			   " gets response "); 
                            
        doggy1.stroke();

        System.out.println("And now there was " + Dogs.getNumberOfDogsInGodsWorld() + " dog");

	System.out.println("And our Lord sayeth: There shall be another dog - insignificant and grey");

	Dogs doggy2 = new Dogs("grey");

	System.out.print("Stroking the insignificant dog with color " + 
                            doggy2.getColor() + 
			   " gets response "); 
                            
        doggy2.stroke();

        System.out.println("And now there were " + Dogs.getNumberOfDogsInGodsWorld() + " dogs");

	System.out.println("And the dark angel sayeth: There shall be a really bad dog - pitch-black");

	BadDogs doggy3 = new BadDogs("pitch-black");

	System.out.print("Stroking the really bad dog with color " + 
                            doggy3.getColor() + 
			   " gets response "); 
                            
        doggy3.stroke();

        System.out.println("And now there were " + Dogs.getNumberOfDogsInGodsWorld() + " dogs");

	Dogs[] godsArray = new Dogs[3];

	System.out.println("And all dogs, whether"+
                      " good or bad, lived in God's array");
	godsArray[0] = doggy1;
	godsArray[1] = doggy2;
	godsArray[2] = doggy3;

        System.out.println("And stroking all"+
            " the dogs in God's array" +
            " resulted in the most polymorphic responses :");

	for (int dog = 0; dog < godsArray.length; dog++ ) {
	    godsArray[dog].stroke();
	}

        System.out.println("\nAnd God called a method of the super class,\n" +
                           "and the super class called a method which\n" +
                           "was redefined in the sub-classes, and God saw every method\n" +
                           "that he had made and, behold, it was very good:");

	for (int dog = 0; dog < godsArray.length; dog++ ) {
	    godsArray[dog].stroke(3);
	}


    }


}
