Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fullweek2;
- public class Day15B {
- public static void main(String[] args) {
- Animal callAnimal = new Animal();
- callAnimal.printInfo();
- System.out.println("---------------");
- Bat callBat = new Bat();
- callBat.printInfo();
- System.out.println("---------------");
- VampireBat callVampireBat = new VampireBat();
- callBat.printInfo();
- }
- }
- class Animal {
- void printInfo() {
- eat();
- sleep();
- soundsLike();
- }
- void eat() {
- System.out.println("It can eat meat and plants");
- }
- void sleep() {
- System.out.println("It sleeps during nighttime");
- }
- void soundsLike() {
- System.out.println("It makes noises");
- }
- }
- class Bat extends Animal {
- @Override void eat() {
- System.out.println("Bats eat fruits");
- }
- @Override void sleep() {
- System.out.println("They are nocturnal animals");
- }
- void soundsLike() {
- System.out.println("Bats make chittering noises");
- }
- @Override
- void printInfo() {
- System.out.println("Bats are flying mammals that are "
- + "capable of true and sustained flight. ");
- super.printInfo();
- }
- }
- class VampireBat extends Bat {
- @Override
- void eat() {
- super.eat();
- System.out.println("They can also hunt for insects");
- }
- void printInfo() {
- System.out.println("Vampire bats are leaf-nosed bats"
- + " currently found in Central and South America");
- super.printInfo();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment