Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package week3;
- public class Day15A {
- public static void main(String[] args) {
- Animal callAnimal = new Animal();
- callAnimal.movement();
- callAnimal.makeSound();
- System.out.println("\n-----(1)-----\n");
- callAnimal.summary();
- System.out.println("\n-----(2)-----\n");
- Dog callDog = new Dog();
- callDog.dogInfo();
- callDog.summary();
- System.out.println("\n-----(3)-----\n");
- Goat callGoat = new Goat();
- callGoat.goatInfo();
- callGoat.summary();
- System.out.println("\n-----(4)-----\n");
- Feline callFeline = new Feline();
- callFeline.summary();
- callGoat.summary();
- System.out.println("\n-----(5)-----\n");
- Cat callCat = new Cat();
- callCat.summary();
- System.out.println("\n-----(6)-----\n");
- Feline callFeline1 = new Cat();
- callFeline1.summary();
- }
- }
- class Animal {
- void movement() {
- System.out.println("It moves with its 4 legs");
- }
- void eat(){
- System.out.println("Its an omnivore");
- }
- void makeSound() {
- System.out.println("The animal is growling");
- }
- void summary() {
- movement();
- eat();
- makeSound();
- }
- }
- class Dog extends Animal {
- void dogInfo() {
- System.out.println("Dogs are house pets");
- }
- @Override
- void makeSound() {
- System.out.println("Dogs can bark");
- }
- }
- class Goat extends Animal {
- void goatInfo() {
- System.out.println("Goats are farm pets");
- }
- @Override
- void eat(){
- System.out.println("Its a herbivore");
- }
- @Override
- void makeSound() {
- System.out.println("Goats can produce sound like Meeeee");
- }
- }
- class Feline extends Animal {
- void felineInfo() {
- System.out.println("Felines belong to the family Felidae, which includes the lions, tigers, jaguars, and wild and domestic cats");
- }
- @Override
- void eat(){
- System.out.println("Its a carnivore");
- }
- @Override
- void summary() {
- felineInfo();
- super.summary();
- }
- }
- class Cat extends Feline {
- void catInfo(){
- System.out.println("Cats are one of the two most common pets in the world");
- }
- @Override
- void summary() {
- catInfo();
- super.summary();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment