Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this is the Main Driver.. it runs
- //it creates a Animal objects
- //both this file Zoo.java and Animal.java must be in same folder
- public class Zoo {
- public static void main(String[] args) {
- //create an Animal object
- Animal tiger = new Animal("carnivore"); //creating a tiger which is a Animal
- //Animal tiger on left declares it on the right of the =
- //is where the cosntructor get called with the value to set diet instance var. to
- //so new Animal("carnivore"); calls the constructor
- String d = tiger.getDiet(); //tiger is the animal object & we are calling the
- // getDiet method on it -- which returns back the String diet for tiger -> carnivore
- //print it out
- System.out.print("The Tiger has a Diet of: " + d);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement