// AnimalsReverseOrder.java Copyright (c) 2005 Kari Laitinen // http://www.naturalprogramming.com // 2005-06-03 File created. // 2005-06-03 Last modification. // This program works like Animals.java, but here the order of // members in class Animal is reversed. This is not the normal // programming style in my programs. class Animal { public void make_speak() { System.out.print( "\n Hello, I am a " + species_name + "." + "\n I have eaten: " + stomach_contents + "\n" ) ; } public void feed( String food_for_this_animal ) { stomach_contents = stomach_contents + food_for_this_animal + ", " ; } public Animal( Animal another_animal ) { species_name = another_animal.species_name ; stomach_contents = another_animal.stomach_contents ; } public Animal( String given_species_name ) { species_name = given_species_name ; stomach_contents = "" ; } String species_name ; String stomach_contents ; } class AnimalsReverseOrder { public static void main( String[] not_in_use ) { Animal cat_object = new Animal( "cat" ) ; Animal dog_object = new Animal( "vegetarian dog" ) ; cat_object.feed( "fish" ) ; cat_object.feed( "chicken" ) ; dog_object.feed( "salad" ) ; dog_object.feed( "potatoes" ) ; Animal another_cat = new Animal( cat_object ) ; another_cat.feed( "milk" ) ; cat_object.make_speak() ; dog_object.make_speak() ; another_cat.make_speak() ; } }