Skip to content

YuriiJavaDev/JavaBasics_Task_304_V0.1

Repository files navigation

Virtual Zoo: Polymorphism & Upcasting (JavaBasics_Task_304_V0.1)

📖 Description

Polymorphism allows objects of different classes to be treated as objects of a common superclass. This project demonstrates Upcasting by treating a Dog instance as a generic Animal. Even though the reference variable is of type Animal, the Java Virtual Machine (JVM) correctly identifies the underlying object at runtime and executes the overridden makeSound() method. This decoupling of the reference type from the actual object type is the foundation of extensible software architecture.

📋 Requirements Compliance

  • Base Class Template: Defined Animal with a default sound implementation.
  • Method Overriding: Specialized the makeSound() behavior in the Dog subclass.
  • Upcasting Demonstration: Assigned a Dog object to an Animal reference variable.
  • Runtime Binding: Verified that the subclass implementation is executed instead of the base class version.
  • Clean Code structure: Organized into logical packages (animal, dog, app).

🚀 Architectural Stack

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

🏗️ Implementation Details

  • Animal: The general abstraction of a zoo inhabitant.
  • Dog: The concrete implementation with specific behavior.
  • ZooLauncherApp: The execution entry point demonstrating polymorphic interaction.

📋 Expected result

Woof!

💻 Code Example

Project Structure:

JavaBasics_Task_304/
├── src/
│   └── com/yurii/pavlenko/
│                 ├── app/
│                 │   └── ZooLauncherApp.java
│                 └── animal/
│                     ├── dog/
│                     │   └── Dog.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.dog.Dog;

public class ZooLauncherApp {

    public static void main(String[] args) {
        Animal pet = new Dog();
        pet.makeSound();
    }
}
package com.yurii.pavlenko.animal;

public class Animal {

    public void makeSound() {
        System.out.println("Some sound...");
    }
}
package com.yurii.pavlenko.animal.dog;

import com.yurii.pavlenko.animal.Animal;

public class Dog extends Animal {

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

⚖️ 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_304_V0.1 Virtual Zoo: demonstrating method overriding and upcasting, proving that an object's behavior is tied to its actual instance type rather than its reference type. 120426_0850

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages