Advertisement
Guest User

zoo

a guest
Apr 8th, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. //this is the Main Driver.. it runs
  2. //it creates a Animal objects
  3. //both this file Zoo.java and Animal.java must be in same folder
  4.  
  5.  
  6. public class Zoo {
  7.      public static void main(String[] args) {
  8.            //create an Animal object
  9.            Animal tiger = new Animal("carnivore"); //creating a tiger which is a Animal
  10.            //Animal tiger on left declares it on the right of the =
  11.            //is where the cosntructor get called with the value to set diet instance var. to
  12.            //so new Animal("carnivore"); calls the constructor
  13.  
  14.           String d = tiger.getDiet(); //tiger is the animal object & we are calling the
  15.           // getDiet method on it -- which returns back the String diet for tiger -> carnivore
  16.  
  17.          //print it out
  18.          System.out.print("The Tiger has a Diet of: " + d);
  19.      }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement