UNIVERSITY EXAMINATION 2023/2024
ORDINARY EXAMINATION FOR THE DEGREE OF
BACHELOR OF SCIENCE IN STATISTICS
SPC 2206: Object Oriented Programming II YEAR II SEM II
Date: WEDNESDAY 17TH APRIL 2024 TIME: 4.00 PM – 6.00 PM
INSTRUCTIONS
Answer Question ONE and any other TWO Questions
Section (30 Marks)
Question One (30 Marks)
a) List three advantages of Encapsulation as used in Java programming. [3 Marks]
b) Differentiate Between JDK And JVM As Used in Java programming [4 Marks]
c) Write a JAVA program for the following narration. [5 Marks]
The unit price of a particular product is 150 shillings if less than 30 units are
purchased 140 shillings it between 30 and 69 are purchased. If the customer
balso has preferred customer status the purchase is subject to 10% discount.
d) Outline four advantages of packages in Java programming [4 Marks]
e) Outline three reasons why Exceptions occur in Java [3 Marks]
f) Write JAVA snippet code to demonstrate the use of THIS key word [4Marks]
g) Describe any four elements of Graphical User Interface Programming in Java. [4 Marks]
h) Describe three benefits of Swing over AWT as applied in java programming [3 Marks]
Page 1 of 3
SECTION TWO (40 Marks)
Attempt TWO questions from this section
Question Two (20 Marks)
a) Outline two differences between methods and constructors as used in Java, [4 Marks]
b) Using super class ‘House’, base class ‘Bedroom’ and a method called ‘Sitroom’, Write a
code snippet to demonstrate runtime polymorphism in Java. [8 Marks]
c) A Java program using a function to determine whether a number is prime or not.
[8 Marks]
Question Three (20 Marks)
a) Distinguish between the following terminologies. [6 Marks]
i. Function definition and function declaration
ii. Class and object
iii. Stubs and skeletons
b) Write a Java code to output the following using For Loop control structure [6 Marks]
*
**
***
****
*****
c) The following is a program that demonstrate one of the concepts of object-oriented
programming
1. import java.io.*;
2. interface Animal {
3. void eat();
4. }
5. interface Mammal {
6. void drink();
7. }
8. class Dog implements Animal, Mammal {
9. public void eat() { System.out.println("Eating"); }
10. public void drink() { System.out.println("Drinking"); }
11. void bark() { System.out.println("Barking"); }
12. }
13. class question {
14. public static void main(String[] args)
15. {
16. Dog d = new Dog();
17. d.eat();
18. d.drink();
19. d.bark();
20. }
Page 2 of 3
21. }
i. Identify the OOP concept demonstrated in the program [2 Marks]
ii. Explain the program and give its output [6 Marks]
Question Four (20 Marks)
a) write a program using an interface to calculate area and perimeter of a circle 7 Marks
b) Explain three drawbacks of Garbage Collection in java programming [6 Marks]
c) Describe three features of Constructors in Java [3 Marks]
d) Explain two advantages of object cloning in java [4 Marks]
Question Five (20 Marks)
a) Write a snippet of a code to demonstrate method overloading as used in Java
Programming [8 Marks]
b) Write a Java Graphical User Interface program that can produce the following interface
using Java swing components . [8 Marks]
c) Differentiate between default constructor and parameterized Constructor using a code
snippet as used in java programming. [4 Marks]
Page 3 of 3