Skip to content

YuriiJavaDev/JavaBasics_Task_284_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Virtual Pets: Basic Inheritance (JavaBasics_Task_284_V0.1)

📖 Description

In Object-Oriented Programming, Inheritance allows a new class to acquire the properties and behaviors of an existing class. This project demonstrates this core concept by creating a base class Animal and a specialized subclass Cat. The Cat class automatically receives the petName field and the eat() method from Animal, proving the power of code reuse. Additionally, the subclass introduces its own specific behavior, meow(), illustrating how hierarchies evolve from general to specific.

📋 Requirements Compliance

  • Superclass Definition: Created Animal with shared state (petName) and behavior (eat).
  • Subclass Specialization: Implemented Cat using the extends keyword to inherit from Animal.
  • Field Reusability: Demonstrated that the subclass can access and use fields defined in the parent class.
  • Extended Behavior: Added a unique meow() method specific only to the Cat class.
  • Clean Architecture: Separated the domain models from the PetLauncherApp entry point.

🚀 Architectural Stack

  • Java 8+ (Inheritance, extends keyword, Access Modifiers)

🏗️ Implementation Details

  • Animal: The base (super) class providing the common blueprint.
  • Cat: The derived (sub) class extending the base functionality.
  • PetLauncherApp: The bootstrap class to instantiate and interact with the virtual pet.

📋 Expected result

Barsik is eating.
Barsik says: Meow!

💻 Code Example

Project Structure:

JavaBasics_Task_284/
├── src/
│   └── com/yurii/pavlenko/
│                 ├── Animal.java
│                 ├── Cat.java
│                 └── PetLauncherApp.java
└── README.md

Code

package com.yurii.pavlenko;

public class PetLauncherApp {

    public static void main(String[] args) {

        Cat cat = new Cat();

        cat.petName = "Barsik";

        cat.eat();
        cat.meow();
    }
}
package com.yurii.pavlenko;

public class Animal {

    public String petName;

    public void eat() {
        System.out.println(petName + " is eating.");
    }
}
package com.yurii.pavlenko;

public class Cat extends Animal {

    public void meow() {
        System.out.println(petName + " says: 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_284_V0.1 Virtual Pets: implementing basic class inheritance and member accessibility from a superclass to a subclass. 300326_1147

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages