Professional Documents
Culture Documents
CONFIDENTIAL /SULIT
1. This question paper is set in English and Bahasa Melayu. ANSWER ALL questions using
ONE LANGUAGE ONLY either ENGLISH or BAHASA MELAYU.
Kertas soalan ini disediakan dalam Bahasa Inggeris dan Bahasa Melayu. JAWAB SEMUA soalan dalam
SATU BAHASA SAHAJA sama ada BAHASA INGGERIS atau BAHASA MELAYU.
PART A/ BAHAGIAN A
INSTRUCTIONS/ ARAHAN
Identify X.
(4)
Pertimbangkan pernyataan berikut:
X adalah pendekatan yang mana suatu kelas memperolehi ciri-ciri kelas yang
lain. Dengan X, kita boleh menggunakan semula medan data dan metod
daripada kelas yang sedia ada.
Kenalpasti X.
3. An attribute of a class has been declared as private with data type integer.
How would you access the value of this attribute from a different class?
(4)
Suatu atribut kelas telah diisytiharkan sebagai private dengan data berjenis
integer. Bagaimanakah anda akan mengakses nilai atribut ini daripada kelas
yang lain?
1
CDOP3203/JAN 2020/F
4. What is the value of the attribute y after a second object of type A being
created?
(4)
Apakah nilai bagi atribut y selepas objek kedua daripada jenis A diwujudkan?
class A {
public A () {
y=y+3;
}
2
CDOP3203/JAN 2020/F
PART B/ BAHAGIAN B
INSTRUCTIONS/ ARAHAN
Attributes:
private int id
private double balance
Methods:
Constructor
Purpose: It has two parameters which have values to be assigned
respectively to all
the attributes of this class
3
CDOP3203/JAN 2020/F
represents
the amount that need to be deposited
Tuliskan satu definisi kelas untuk memodelkan suatu akaun bank. Maklumat
berkenaan kelas ini diberikan di bawah:
Atribut:
private int id
private double baki
Metod:
Metod Pembina
Tujuan: Metod ini mempunyai dua parameter yang mana nilainya akan
diumpukkan
masing-masing kepada semua atribut yang ada di dalam kelas ini
4
CDOP3203/JAN 2020/F
2. Create a class named Person and its two subclasses named Student and
Employee.
A Person has a name, address, phone number and email address as private
attributes. In addition, it also has a constructor, accessor and mutator
methods for all the attributes. This class also has a display() method in
order to display the value of the attributes.
Note: Override the display() method in each class to display the value of the
attributes in the both superclass and the subclass.
5
CDOP3203/JAN 2020/F
Hasilkan satu kelas dengan nama Person dan dua subkelasnya bernama Student
dan Employee.
Seorang Person mempunyai nama, alamat, nombor telefon dan alamat email
sebagai atribut private. Sebagai tambahan, ia juga mempunyai metod pembina,
metod-metod accessor dan mutator bagi semua atribut. Kelas ini juga
mempunyai metod display() bagi memaparkan nilai-nilai atribut.
Nota: Batalkan metod display() bagi setiap kelas untuk memaparkan nilai
atribut bagi kedua-dua superkelas dan subkelas.
6
CDOP3203/JAN 2020/F
3. Write an Applet program to produce the following user interface. You are
not required to write the codes for the event handling.
Tuliskan aturcara Applet untuk menghasilkan antara muka seperti berikut. Anda
tidak diperlukan untuk menulis kod bagi pengendalian peristiwa.