Advertisement
Guest User

inheritance

a guest
Oct 17th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. Animal = Alliance
  2. Dog = House
  3. Cat = Army
  4.  
  5.  
  6. When you convert to alliance, how do you know whether you need battle strength of house and army
  7.  
  8.  
  9. Abstract class - gets the common methods between the two classes.
  10. Common stuff - getName, getYears, getBanner
  11.  
  12. Cat and Dog both have sound() but have different implementation (dog has woof, cat has meow)
  13.  
  14. Animal ani = new Cat()
  15. ani.sound() //
  16.  
  17. Interfaces only have abstract methods // public abstract String sound();
  18.  
  19. Wrong: newArr[ii] = new Cat (arr[ii]);
  20. Correct: arr[ii].clone(); Since we don't know the datatype
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement