Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal {
- public void checkStatus () {
- System.out.println("Your dog is alive!");
- }
- }
- class Dog extends Animal {
- int age;
- String breed;
- public Dog(int dogsAge, String dogsBreed){
- age = dogsAge;
- breed = dogsBreed;
- }
- public void bark(){
- System.out.println("Woof!");
- }
- public void run(int meters){
- System.out.println("Your dog of" + age +" years old, ran " + meters + " meters!");
- }
- public int getAge(){
- return age;
- }
- public static void main(String[] args) {
- Dog spike = new Dog(7, "spaniel");
- Dog spot = new Dog (5, "bulldog");
- spike.bark();
- spot.bark();
- spike.bark();
- spot.bark();
- spike.bark();
- spike.run(200);
- spike.bark();
- System.out.println(spike.getAge());
- System.out.println(spot.getAge());
- spike.checkStatus();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement