Page 321 - Computer_Science_F5
P. 321
Computer Science Table 5.3: Instance of a class “Car” Honda
Nissan
Toyota
Make= “Honda”
Make= “Nissan”
Make= “Toyota”
Color= “Black”
Color= “Purple”
Color= “Silver”
FOR ONLINE READING ONLY
StartEngine()
Accelerate()
Accelerate() StartEngine() StartEngine()
Accelerate()
Exercise 5.1 Key principles of OOP in Java
1. Develop a class named Car with Abstraction
properties make, model, and year. The term abstraction means dealing with
Create three objects of this class ideas rather than events. It essentially
and print their details. deals with keeping information hidden
2. Implement a class ‘Rectangle’ with and only presenting the user with what
properties ‘length’ and ‘width’. is necessary.
Add methods to calculate the area
and perimeter of the rectangle. Activity 5.1:
Create an object of the class and
display the area and perimeter. Exploring of abstraction in the
3. Write a program of a class surrounding environments
‘Student’ with instance variables Aim:
‘name’ and ‘age’, and a class To identify and describe examples of
variable ‘schoolName’. Create abstraction in various environment.
three instances of the ‘Student’
class and assign different values Materials: TV, Surrounding
to the instance variables but the environments (such as classroom,
same value to the class variable. play ground, home and library) or
Print the details of each student. Internet
4. Create a class ‘BankAccount’
with instance variables Instructions:
‘accountNumber’ and ‘balance’. Everyone knows how to turn on the
Add methods to deposit and TV, but understanding how it operates
withdraw money, and check the is not necessary. In abstraction, simple
balance. Instantiate an object entities such as variables, classes, and
of the class and perform some objects can represent more complex
transactions. underlying code and data. It prevents
doing the same task more than once.
312
for Advanced Secondary Schools
Computer Science Form 5.indd 312 23/07/2024 12:34

