HarrJ

Day 15

Jul 5th, 2024
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. package fullweek2;
  2.  
  3. public class Day15B {
  4.     public static void main(String[] args) {
  5.         Animal callAnimal = new Animal();
  6.         callAnimal.printInfo();
  7.         System.out.println("---------------");
  8.         Bat callBat = new Bat();
  9.         callBat.printInfo();
  10.         System.out.println("---------------");
  11.         VampireBat callVampireBat = new VampireBat();
  12.         callBat.printInfo();
  13.     }
  14. }
  15.  
  16. class Animal {
  17.     void printInfo() {
  18.         eat();
  19.         sleep();
  20.         soundsLike();
  21.     }
  22.    
  23.     void eat() {
  24.         System.out.println("It can eat meat and plants");
  25.     }
  26.    
  27.     void sleep() {
  28.         System.out.println("It sleeps during nighttime");
  29.     }
  30.    
  31.     void soundsLike() {
  32.         System.out.println("It makes noises");
  33.     }
  34. }
  35.  
  36. class Bat extends Animal {
  37.     @Override void eat() {
  38.         System.out.println("Bats eat fruits");
  39.     }
  40.    
  41.     @Override void sleep() {
  42.         System.out.println("They are nocturnal animals");
  43.     }
  44.  
  45.     void soundsLike() {
  46.         System.out.println("Bats make chittering noises");
  47.     }
  48.  
  49.     @Override
  50.     void printInfo() {
  51.         System.out.println("Bats are flying mammals that are "
  52.                 + "capable of true and sustained flight. ");
  53.         super.printInfo();
  54.     }
  55. }
  56.  
  57. class VampireBat extends Bat {
  58.  
  59.     @Override
  60.     void eat() {
  61.         super.eat();
  62.         System.out.println("They can also hunt for insects");
  63.     }
  64.    
  65.     void printInfo() {
  66.         System.out.println("Vampire bats are leaf-nosed bats"
  67.                 + " currently found in Central and South America");
  68.         super.printInfo();
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment