Activity 1: Class Definition
-
Task 1: Define a class
Personwith propertiesnameandage, and a method to return a greeting message. Create an instance of the class and log the greeting message. -
Task 2: Add a method to the
Personclass that updates the age property and logs the updated age.
Activity 2: Class Inheritance
-
Task 3: Define a class
Studentthat extends thePersonclass. Add a propertystudentIDand a method to return the student ID. Create an instance of theStudentclass and log the student ID. -
Task 4: Override the greeting method in the
Studentclass to include the student ID in the message. Log the overridden greeting message.
Activity 3: Static Methods and Properties
-
Task 5: Add a static method to the
Personclass that returns a generic greeting message. Call this static method without creating an instance of the class and log the message. -
Task 6: Add a static property to the
Studentclass to keep track of the number of students created. Increment this property in the constructor and log the total number of students.
Activity 4: Getters and Setters
-
Task 7: Add a getter method to the
Personclass to return the full name (assume afirstNameandLastNameproperty). Create an instance and log the full name using the getter. -
Task 8: Add a setter method to the
Personclass to update the name properties (firstNameandLastName). Update the name using the setter and log the updated full name.
Activity 5: Private Fields (Optional)
-
Task 9: Define a class
Accountwith private fields forbalanceand a method to deposit and withdraw money. Ensure that the balance can only be updated through these methods. -
Task 10: Create an instance of the
Accountclass and test the deposit and withdraw methods, logging the balance after each operation.
-
Basic Class Script: Write a script that defines a
Personclass with properties and methods, creates instances, and logs messages. -
Class Inheritance Script: Create a script that defines a
Studentclass extendingPerson, overrides methods, and logs the results. -
Static Methods and Properties Script: Write a script that demonstrates static methods and properties in classes.
-
Getters and Setters Script: Create a script that uses getters and setters in a class.
-
Private Fields Script: Write a script that defines a class with private fields and methods to manipulate these fields (optional).
By the end of these activities, you will:
-
Define and use classes with properties and methods.
-
Implement inheritance to extend classes.
-
Utilize static methods and properties.
-
Apply getters and setters for encapsulation.
-
Understand and use private fields in classes (optional).
