SPC 2206 Spe 2207 Object Oriented Programming II Year II Semester II-1
SPC 2206 Spe 2207 Object Oriented Programming II Year II Semester II-1
Question One
a) Describe the following Object Oriented terminologies as used in Java.
(3 Marks)
i. Packages
ii. Interfaces
iii. Garbage collection
b) Using sample codes, describe the term Java Socket as used in Java programming.
(3 Marks)
c) Write a code snippet to demonstrate how to declare a constant using the final
keyword in Java. (3 Marks)
d) Distinguish between inheritance and polymorphism. (4 Marks)
e) Describe the term namespace as used in Java Programming. (2 Marks)
f) Write a code snippet to create the frame below in Java. (4 marks)
Page 1 of 3
Question Three
a) Using super class ‘Animal’, base class ‘Horse’ and a method called ‘sound’, Write a
code snippet to demonstrate runtime polymorphism in Java. (7 Marks)
b) Write a Java program that can take two parameters and determine whether they are
equal or not. The program should be implemented using the following: a
constructor and a method named ‘compare’. (7 Marks)
c) Distinguish between the following terminologies. (6 Marks)
i. Function definition and function declaration
ii. Class and object
iii. Stubs and skeletons
Question Four
a) A second year Bachelor of Science in Mathematics and Computer Science student
was tasked to write a Java program that can calculate area of various shapes.
Assuming you are the student, using the concept of inheritance and class ‘Rectangle’
as the base class, ‘Square’ as the derived class. Write the above Java program.
(8 Marks)
b) Write a code snippet to demonstrate how a parameterized constructor can be used
to initialize data members ‘length’ and ‘width’ in class ‘Shape’. (6 Marks)
c) Using for structure, write an Object Oriented Program to calculate sum of odd
numbers between 15 and 70. (6 Marks)
Page 2 of 3
Question Five
a) Using sample codes, describe three ways an object can be unreferenced in Java.
(6 Marks)
b) Using the knowledge of Sockets, write a TCP Server code snippet that sends the
Client the current date and time when the Client connects; then closes the
connection. (6 Marks)
c) Using class ‘Student’, write code snippets to describe two types of constructors that
can be used in Java programming. (8 Marks)
Page 3 of 3