Guest User

Untitled

a guest
Jun 28th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. abstract public class Animal {
  2.  
  3. public int nLegs = 0;
  4. public void numLegs(int nLegs) {
  5. this.nLegs = nLegs;
  6. }
  7.  
  8.  
  9. public abstract int getLegs();
  10.  
  11. //Constructor
  12. public Animal (int nLegs) {
  13. numLegs(nLegs)
  14. }
  15. }
  16.  
  17. public class Monkey extends Animals {
  18.  
  19. public int getLegs(){
  20. return this.nLegs;
  21. }
  22. public monkey(){
  23. super(2);
  24. }
  25.  
  26. public void saySome(){
  27. System.out.println("Hello, I am a monkey!");
  28. }
  29.  
  30. }
  31.  
  32. public class MainClass{
  33.  
  34. public static void main(String []args){
  35.  
  36. Animal jay = new Monkey ();
  37. System.out.println(jay.nLegs);
  38.  
  39. /* jay.saySome()*/
  40. ((Monkey) jay).saySome();
  41.  
  42. }
  43. }
Add Comment
Please, Sign In to add comment