Skip to content

YuriiJavaDev/JavaBasics_Task_303_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Animal Simulation: Dynamic Binding (JavaBasics_Task_303_V0.1)

📖 Description

Polymorphism is one of the pillars of OOP, allowing a single interface to represent different underlying forms. This project explores Dynamic Binding. When a method is called on a reference of a superclass (Animal), Java determines which implementation to execute based on the actual object type at runtime (Cat). Even if the call happens inside a superclass method (sleep()), the overridden version in the subclass takes precedence. This enables highly flexible and extensible code architectures.

📋 Requirements Compliance

  • Dynamic Binding: Demonstrated that this.makeSound() inside a parent method calls the child's override.
  • Polymorphic Reference: Used an Animal type variable to hold a Cat instance.
  • Method Overriding: Correctly specialized the makeSound() behavior for the Cat class.
  • Architectural Integrity: Maintained professional package separation for domain logic.

🚀 Architectural Stack

  • Java 8+ (Polymorphism, Dynamic Binding, Inheritance)

🏗️ Implementation Details

  • Animal: Defines the base behavioral contract and the sleep() template.
  • Cat: Provides the specific sound implementation.
  • SimulationLauncherApp: Entry point. Demonstrates polymorphic behavior.

📋 Expected result

Animal is going to sleep...
Meow!

💻 Code Example

Project Structure:

JavaBasics_Task_303/
├── src/
│   └── com/yurii/pavlenko/
│                 ├── app/
│                 │   └── SimulationLauncherApp.java
│                 └── animal/
│                     ├── cat/
│                     │   └── Cat.java
│                     └── Animal.java
├── LICENSE
├── TASK.md
├── THEORY.md
└── README.md

Code

package com.yurii.pavlenko.app;

import com.yurii.pavlenko.animal.Animal;
import com.yurii.pavlenko.animal.cat.Cat;

public class SimulationLauncherApp {

    public static void main(String[] args) {
        Animal mysteriousCreature = new Cat();
        mysteriousCreature.sleep();
    }
}
package com.yurii.pavlenko.animal;

public class Animal {

    public void makeSound() {
        System.out.println("Some sound.");
    }

    public void sleep() {
        System.out.println("Animal is going to sleep...");
        this.makeSound();
    }
}
package com.yurii.pavlenko.animal.cat;

import com.yurii.pavlenko.animal.Animal;

public class Cat extends Animal {

    @Override
    public void makeSound() {
        System.out.println("Meow!");
    }
}

⚖️ License

This project is licensed under the MIT License.

Copyright (c) 2026 Yurii Pavlenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...

License: MIT

About

This is a tutorial project. JavaBasics_Task_303_V0.1 Animal Simulation: demonstrating polymorphism and dynamic method binding where the runtime object type determines behavior. 070426_1159

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages