Lab Task 3
Lab Task 3
Theoretical Description
Classes and Objects: In Java, a class is a blueprint for creating objects. A class defines the
structure and characteristics (properties and behaviors) that its objects will have. Objects are
instances of classes, and they represent real-world entities or concepts.
Properties (Attributes): Properties are variables defined within a class that represent the state
or characteristics of objects. These properties are also referred to as attributes or fields. In this
lab, you will create a "Person" class with two properties: name and age. These properties
encapsulate information about a person.
Lab Task
Task 1: Creating a Class
• Create a new Java class named "Person."
• Define two properties within the "Person" class: name (a string) and age (an integer).
• Create a constructor that allows you to initialize these properties when an object is
created.
9
BS (Software Engineering) 2023
• In the main method of another class, create two objects of the "Person" class.
• Initialize their name and age properties using the constructor.
• Print out the details of these two persons.
Code Help:
// Task 1: Creating a Class
this.name = name;
this.age = age;
10
BS (Software Engineering) 2023
age++;
return name;
this.name = name;
return age;
this.age = age;
person1.introduce();
person2.introduce();
11
BS (Software Engineering) 2023
person1.birthday();
12