📑 LABORATORY ACTIVITY
JAVA CODING
Task 1 Code & Output:
Tasks 2&3
Code & Output:
Task 4 Code & Output:
Tasks 5 & 6 Code & Output:
Guide Question Answers:
1. What is the main difference between a class and an object?
A class is a blueprint or template that defines the common attributes (data or
properties) and behaviors (methods or functions) that a group of objects will
share. Imagine of a class as the design plan for a house – it describes what the
house will have (rooms, windows, doors) but it is not the actual house itself.
While objects are the concrete instance of a class. It is a real-world entity that is
created based on the specifications defined by a class. Objects occupy memory
and have a specific state, meaning their attributes have values. Using the house
analogy, an object is the actual house built from the blueprint, with specific
details like the color of the walls, the type of furniture, and the number of
occupants. Multiple objects can be created from a single class, each with its own
unique state, but all adhering to the structure defined by the class.
2. Why are methods important in object-oriented programming?
Methods are important because it is the one who makes the actions of the
program. It helps to reuse codes, make it cleaner, and easier to understand. Instead
of repeating the same algorithm on the main class we can just call the method
anytime.
3. When should you use a static method instead of an instance method?
We use the static method when the action or information doesn’t need a specific
object to work. Like showing the university name — it’s the same for everyone,
so there is no need to create an object. Instance methods are used when each
object has different data.
Reflection:
The concept of class and object reminds me of how things work in real life here in SLSU
CIT–BSIT. For example, we students are like “objects,” and the course BSIT is like the
“class.” We all follow the same structure, but we have our own names, IDs, and sections.
For me, the most useful OOP concept so far is using methods because they make coding
easier and more organized. Instead of writing long lines repeatedly, I can just call a
method. It saves time and makes my program look neat.