OOP - FIIT STU

Cvičenie 5

Interfaces & Java Initialization Order: The Plant Shop

Cvičenie 5 - GUI & Plánovanie

Úlohy

  • Pokračujte v práci na svojom semestrálnom projekte. Nezabudnite pracovať pravidelne, a to tempom minimálne 2 commity týždenne. Každý commit by mal predstavovať zmysluplnú funkciu alebo vylepšenie.
  • Neváhajte požiadať o pomoc a prekonzultovať svoje nápady s učiteľom.
  • Odporúča sa začať s tromi časťami projektu: doménovým modelom – logikou, testovacím prostredím a užívateľským rozhraním.

Ďalšie odovzdanie je Zadanie 2 - checkpoint. Dátum 29.03.2026.

Java Úlohy

Task 9 — Interfaces & Java Initialization Order: The Plant Shop

Understanding Interfaces, Inheritance, and How Java Brings Your Code to Life

In this task you will build a plant shop system where different plants (flowers, succulents, herbs) each have unique growing and treatment behaviours defined through interfaces you design yourself. Along the way you will explore how Java actually initializes classes and objects — the exact order in which static blocks, instance blocks, field initializers, and constructors execute, including across an inheritance hierarchy.

This task has two parts:

PartWhat you will learn
Part 1 — Interfaces & the Plant ShopDesign and implement your own interfaces; have classes implement multiple interfaces; understand interface contracts
Part 2 — Initialization Order PlaygroundDiscover — by running code and observing output — the precise order Java uses to load classes, initialize fields, execute initializer blocks, and call constructors

Provided files

All files live in package org.jikvict.tasks.exposed:

FileStatusDescription
Plant.javaProvidedAbstract base class for all plants — contains static/instance initializer blocks and prints initialization messages
PlantShop.javaProvidedA simple shop that holds plants — students add plants and interact with them
InitializationPlayground.javaProvidedA playground class for experimenting with initialization order — run it, read the output, answer the questions
Main.javaProvidedEntry point — uncomment sections as you implement

Do not change method signatures or access modifiers in provided files. You may add private helper methods if you need them.



Summary

What to createType
Growable.javaInterface (you write it)
Treatable.javaInterface (you write it)
Sellable.javaInterface (you write it)
Flower.javaClass extending Plant, implementing Growable, Treatable
Succulent.javaClass extending Plant, implementing Growable
Herb.javaClass extending Plant, implementing Growable, Treatable, Sellable

On this page