Skip to content

YuriiJavaDev/JavaBasics_Task_287_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Fruit Shop: Hierarchical Inheritance (JavaBasics_Task_287_V0.1)

📖 Description

In cataloging systems, objects are grouped by shared characteristics. This project demonstrates Hierarchical Inheritance by establishing a base Fruit class. Both Apple and Banana subclasses inherit the fruitColor field and the printColor() method. This design allows for a unified way to handle different fruit types while maintaining the flexibility to add unique properties to specific fruits in the future without duplicating the core logic of the superclass.

📋 Requirements Compliance

  • Common Supertype: Created a Fruit class as the root for all fruit types.
  • State Inheritance: Leveraged the fruitColor field in multiple distinct subclasses.
  • Method Sharing: Used the inherited printColor() method to display specific data for different objects.
  • Scalability: Designed the architecture to support adding new fruits (e.g., Orange, Grape) easily.
  • Clean Architecture: Followed the package structure and separated entry point logic.

🚀 Architectural Stack

  • Java 8+ (Inheritance, Member Access, Polymorphic Behavior)

🏗️ Implementation Details

  • Fruit: The superclass defining name and color attribute and display logic.
  • Apple / Banana: Specialized subclasses inheriting from the base.
  • ShopLauncherApp: The bootstrap class for demonstrating fruit property management.

📋 Expected result

Color Apple: Red
Color Banana: Yellow

💻 Code Example

Project Structure:

JavaBasics_Task_287/
├── src/
│   └── com/yurii/pavlenko/
│                 ├── Fruit.java
│                 ├── Apple.java
│                 ├── Banana.java
│                 └── ShopLauncherApp.java
└── README.md

Code

package com.yurii.pavlenko;

public class ShopLauncherApp {

    public static void main(String[] args) {

        Apple apple = new Apple();
        apple.fruitName = "Apple";
        apple.fruitColor = "Red";

        Banana banana = new Banana();
        banana.fruitName = "Banana";
        banana.fruitColor = "Yellow";

        apple.printColor();
        banana.printColor();
    }
}
package com.yurii.pavlenko;

public class Fruit {

    public String fruitColor;
    public String fruitName;

    public void printColor() {
        System.out.println("Color " + fruitName + ": " + fruitColor);
    }
}
package com.yurii.pavlenko;

public class Apple extends Fruit {
}
package com.yurii.pavlenko;

public class Banana extends Fruit {
}

⚖️ 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_287_V0.1 Fruit Shop: implementing hierarchical inheritance to manage common properties like fruit color across different subclasses. 300326_1307

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages