HarrJ

Day 15

Aug 16th, 2023 (edited)
1,141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. package week3;
  2.  
  3. public class Day15A {
  4.     public static void main(String[] args) {
  5.         Animal callAnimal = new Animal();
  6.        
  7.         callAnimal.movement();
  8.         callAnimal.makeSound();
  9.         System.out.println("\n-----(1)-----\n");
  10.         callAnimal.summary();
  11.         System.out.println("\n-----(2)-----\n");
  12.         Dog callDog = new Dog();
  13.         callDog.dogInfo();
  14.         callDog.summary();
  15.         System.out.println("\n-----(3)-----\n");
  16.         Goat callGoat = new Goat();
  17.         callGoat.goatInfo();
  18.         callGoat.summary();
  19.         System.out.println("\n-----(4)-----\n");
  20.         Feline callFeline = new Feline();
  21.         callFeline.summary();
  22.         callGoat.summary();
  23.         System.out.println("\n-----(5)-----\n");
  24.         Cat callCat = new Cat();
  25.         callCat.summary();
  26.         System.out.println("\n-----(6)-----\n");
  27.         Feline callFeline1 = new Cat();
  28.         callFeline1.summary();
  29.     }
  30. }
  31.  
  32. class Animal {
  33.     void movement() {
  34.         System.out.println("It moves with its 4 legs");
  35.     }
  36.    
  37.     void eat(){
  38.         System.out.println("Its an omnivore");
  39.     }
  40.    
  41.     void makeSound() {
  42.         System.out.println("The animal is growling");
  43.     }
  44.    
  45.     void summary() {
  46.         movement();
  47.         eat();
  48.         makeSound();
  49.     }
  50. }
  51.  
  52. class Dog extends Animal {
  53.     void dogInfo() {
  54.         System.out.println("Dogs are house pets");
  55.     }
  56.    
  57.     @Override
  58.     void makeSound() {
  59.         System.out.println("Dogs can bark");
  60.     }
  61. }
  62.  
  63. class Goat extends Animal {
  64.     void goatInfo() {
  65.         System.out.println("Goats are farm pets");
  66.     }
  67.    
  68.     @Override
  69.     void eat(){
  70.         System.out.println("Its a herbivore");
  71.     }
  72.    
  73.     @Override
  74.     void makeSound() {
  75.         System.out.println("Goats can produce sound like Meeeee");
  76.     }
  77. }
  78.  
  79. class Feline extends Animal {
  80.     void felineInfo() {
  81.         System.out.println("Felines belong to the family Felidae, which includes the lions, tigers, jaguars, and wild and domestic cats");
  82.     }
  83.    
  84.     @Override
  85.     void eat(){
  86.         System.out.println("Its a carnivore");
  87.     }
  88.  
  89.     @Override
  90.     void summary() {
  91.         felineInfo();
  92.         super.summary();
  93.     }
  94. }
  95.  
  96. class Cat extends Feline {
  97.     void catInfo(){
  98.         System.out.println("Cats are one of the two most common pets in the world");
  99.     }
  100.    
  101.     @Override
  102.     void summary() {
  103.         catInfo();
  104.         super.summary();
  105.     }    
  106. }
  107.    
Advertisement
Add Comment
Please, Sign In to add comment