Don't like ads? PRO users don't see any ads ;-)
Guest

WORST EVER

By: a guest on Jul 30th, 2012  |  syntax: None  |  size: 0.89 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Write a program that has three classes
  2.  
  3. Animal
  4. Cat
  5. Horse
  6.  
  7. Create an inheritance structure between them and make sure that each class has appropriate attributes.  Each class should have a toString method that prints out the type of animal and the top class should be abstract.  The following class should work with your code.
  8.  
  9.  
  10.  
  11. class BreakStudentCode {
  12.  
  13.  public static void main(String[] argv) {
  14.  
  15.  Animal myAnimal;
  16.  
  17.  myAnimal = new Cat();
  18.  
  19.  exampleMethod(myAnimal);
  20.  
  21.  }
  22.  
  23.  public static void exampleMethod(Animal anAnimal) {
  24.  
  25.  System.out.println(anAnimal);
  26.  
  27.  }
  28.  
  29. }
  30.  
  31.  
  32.  
  33. Finally
  34.  
  35. 1.       Modify this code to ask for which animal the user has
  36.  
  37. 2.       Ask for the attributes appropriate to that animal.  You will need to modify the classes and constructors
  38.  
  39. 3.       Print that animal plus its attributes back out using the exampleMethod.//You are not to modify this method