The transition from a class (blueprint) to an object (instance) is the core of Java programming. This project demonstrates the "lifecycle" of a virtual pet. We declare a Cat template, allocate memory using the new keyword, and then manually define its unique characteristics: "Barsik", aged 3. This process, known as object instantiation, creates a concrete entity in the JVM's Heap memory.
- Object Instantiation: Successfully used the
newkeyword to create aCatinstance. - State Assignment: Manually assigned "Barsik" and 3 to the object fields.
- Data Verification: Implemented a reporting mechanism to confirm the pet's attributes.
- Architectural Separation: Divided responsibilities into Model, Service, and Reporter layers.
- Naming Conventions: Followed PascalCase for classes and camelCase for variables.
- Java 8+ (Object Instantiation, Field Access)
- Cat: The Model. Stores
catNameandcatAge. - PetInitializer: The Service. Handles the "birth" and data assignment.
- PetReporter: The View. Displays the pet's status.
- VirtualPetApp: The Orchestrator. Coordinates the creation and verification process.
[SYSTEM]: A new pet has been created!
Pet Name: Barsik, Age: 3
Project Structure:
JavaBasics_Task_232/
├── src/
│ └── com/
│ └── yurii/
│ └── pavlenko/
│ ├── Cat.java (Model)
│ ├── PetInitializer.java (Logic of creation)
│ ├── PetReporter.java (Console output)
│ └── VirtualPetApp.java (Entry point)
└── README.md
Code
package com.yurii.pavlenko;
public class VirtualPetApp {
public static void main(String[] args) {
PetInitializer initializer = new PetInitializer();
PetReporter reporter = new PetReporter();
System.out.println("[SYSTEM]: A new pet has been created!");
Cat myCat = initializer.createBarsik();
reporter.confirmExistence(myCat);
}
}package com.yurii.pavlenko;
public class PetInitializer {
public Cat createBarsik() {
Cat barsik = new Cat();
barsik.catName = "Barsik";
barsik.catAge = 3;
return barsik;
}
}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