Advertisement
MrDoyle

OOP) Intro version 1

Apr 9th, 2021
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. class Animal {
  2.  
  3.     public void checkStatus () {
  4.         System.out.println("Your dog is alive!");
  5.     }
  6. }
  7.  
  8. class Dog extends Animal {
  9.  
  10.     int age;
  11.     String breed;
  12.  
  13.     public Dog(int dogsAge, String dogsBreed){
  14.  
  15.         age = dogsAge;
  16.         breed = dogsBreed;
  17.     }
  18.  
  19.     public void bark(){
  20.  
  21.         System.out.println("Woof!");
  22.     }
  23.  
  24.     public void run(int meters){
  25.         System.out.println("Your dog of" + age +" years old, ran " + meters + " meters!");
  26.     }
  27.  
  28.     public int getAge(){
  29.  
  30.         return age;
  31.     }
  32.  
  33.  
  34.     public static void main(String[] args) {
  35.  
  36.         Dog spike = new Dog(7, "spaniel");
  37.         Dog spot = new Dog (5, "bulldog");
  38.         spike.bark();
  39.         spot.bark();
  40.         spike.bark();
  41.         spot.bark();
  42.         spike.bark();
  43.  
  44.         spike.run(200);
  45.         spike.bark();
  46.         System.out.println(spike.getAge());
  47.         System.out.println(spot.getAge());
  48.         spike.checkStatus();
  49.  
  50.     }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement