Cit383 2022 2
Cit383 2022 2
University Village, Plot 91, Jabi Cadastral Zone, Nnamdi Azikiwe Expressway, Abuja
FACULTY OF SCIENCES
Computer Science Department
2022_2 EXAMINATION
A programmer has created the following class to represent the employee records
public class Employee {
a) Write a constructor for class Employee. The constructor should have two parameters
which initialise the object fields.
(6 marks)
Page 1 of 5
Grace Omotoso is the HR Manager
Question Two
a) To overload constructors and methods, we simply declare them with different signatures.
What is meant by signature?
(3 marks)
b) Create a class called OverloadedMethods and provide three overloaded public method
called FunctionOverload within this class. The first method should accept two integer
values as its arguments and return an integer. The second method should accept an
integer value, a double value and another integer value in that order and return a double.
The third method should accept two double values as its argument and not return an
argument.
(10 marks)
c) Within the same class OverloadedMethods and provide a constructor for the class that
behaves like the default constructor.
(2 marks)
d) Highlight five (5) features of Interfaces in Java. (5 marks)
Question Three
a) Define Encapsulation. (3 marks)
b) Define Inheritance. (3 marks)
c) Define Polymorphism. (3 marks)
Page 2 of 5
d) Given a class CourseMembers as shown below, modify the class into a form that promotes
data hiding.
public class Member {
protected String firstname;
protected String lastname;
protected int mathscore;
protected int englishscore;
protected int sciencescore;
public Member (String first, String last, int course1, int course2,
int course3)
{
Firstname = first;
Lastname = last;
Mathscore = course1;
Englishscore = course2;
Sciencescore = course3;
}
public double getAverage()
{
return (mathscore + englishscore + sciencescore)/3;
}
(5 marks)
e) Given a class cup as follows:
class cup {
void addLiquid (Liquid liq){
// swirl clockwise
}
}
Create two classes both with the name teaCup. One class will inherit the method
addLiquid() and the other will override it.
(6 marks)
Question Four
a) What is an Object? (2
marks)
Page 3 of 5
c) Differentiate between an executable class and a non-executable class. (2
marks)
Create three accessor methods to retrieve the value of each these variables and a
method to format the output of the time to 12:30:45
(6 marks)
e) Create an executable class CircleProperties that prompts a user to enter the radius of a
circle and computes the perimeter and the area of the circle. You must make use of the
Math.PI static field of the Math class for these computations. The format for receiving
the radius and displaying the results is as follows:
Enter a value for Radius:
The Perimeter is:
The Area is:
(9 marks)
Question Five
a) Enumerate two (2) functions of a destructor. (3 marks)
b) What is meant by Data hiding? (5 marks)
c) Consider a Java package named – Employee – with the following classes – Name,
Address, Department – write the syntax for:
i. importing each class individually (for all classes)
ii. importing all classes (at the same time).
iii. Instantiating an object of the classes – Name and Address.
(7 marks)
Page 4 of 5
d) Outline the stand syntax used to declare an indexer (3
marks)
e) State two limitations of overloading True and False operators (2
marks)
Page 5 of 5