Get premium membership and access revision papers, questions with answers as well as video lessons.
Got a question or eager to learn? Discover limitless learning on WhatsApp now - Start Now!

Object Oriented Programming Concepts Question Paper

Object Oriented Programming Concepts 

Course:Diploma In Business Information Technology

Institution: The Aga Khan University question papers

Exam Year:2008



1
STRATHMORE UNIVERSITY
FACULTY OF INFORMATION TECHNOLOGY
Diploma in Business Information Technology
END OF SEMESTER EXAMINATION
DBT 1204: OBJECT ORIENTED PROGRAMMING CONCEPTS
DATE: April 2008 TIME: 2 Hours
INSTRUCTIONS
ANSWER QUESTION ONE AND ANY OTHER TWO

Question 1
a) Distinguish between the following (10marks)
i. Default constructor and Copy constructor
ii. Inheritance and polymorphism
iii. Data hiding and data abstraction
iv. Overriding and overloading
v. Abstract class and java interface
b) What does it mean to say that a method name has been coerced to a different
type? (2marks)
c) What does it mean to say that a method name has been overloaded? (2marks)
d) What are the benefits of polymorphism? (6marks)
TOTAL MARKS 20MARKS
Question 2
a. In an object oriented inheritance hierarchy, each level is a more specialized form
of the preceding level. Give an example of a hierarchy found in everyday life that
has this property. Illustrate your answer using a diagram. (5marks)
b. Here is a bank account class
class bankAccount{
//data members
private String ownerName;
private double balance;
2
private int account_number;
//constructor
public bankAccount{
ownerName="unassigned";
balance=0.0;
}
//adds the passed amount to the balance
public void add(double amt){
balance=balance+amt;
}
//deducts the passed amount from the balance
public void deduct(double amt){
balance=balance-amt;
}
//returns the current balance of this account
public double getCurrentBalance(){
return balance;
}
//returns the name of the account's owner
public void setOwnerName(String name){
ownerName=name;
}
}
Using the bankAccount class, write a program to test the methods as follows (15marks)
i. Create 3 bankAccounts
ii. Credit account1 with kshs 5000.00
iii. Credit accout2 with kshs 7500.00
iv. Debit account3 with kshs 7500.00
v. Display all the account numbers and their balances.
TOTAL MARKS 20MARKS
Question 3
a. What will be the output of the following code? (6marks)
3
class Q3Main{
public static void main(String args[]){
QuestionThree q3;
q3=new QuestionThree();
q3.init();
q3.count=q3.increment() + q3.increment();
System.out.println(q3.increment());
}
}
class QuestionThree{
public int count;
public void init(){
count=1;
}
public int increment(){
count=count+1;
return count;
}
}
b. How do you call the superclass’s constructor from its subclass? (2marks)
c. What does it mean when a method is declared final? (2marks)
d. Explain polymorphism? How does polymorphism promote extensibility?
(4marks)
e. Imagine you are given the task of designing an airline reservation system
that keeps tracks of flights for a commuter airline. List the classes you
think would be necessary for designing such a system. Describe the data
values and methods you would associate with each class you identify.
(6mark)
TOTAL MARKS 20MARKS
Question 4
a. What are some of the benefits of development classes using inheritance, rather
than development each new class from scratch? (2marks)
b. Using a UML diagram, show the use of inheritance in a problem domain which
you should describe briefly. (3marks)
4
c.
i. Create a class called Employee that includes 3 pieces of information as
instance variables; a first name (type string), a last name (type string) and
a monthly salary (double). Your class should have a constructor that
initializes the 3 instance variables. (5marks)
ii. Provide a set and a get method for each instance variable. If the monthly
salary is not positive, set it to 0.0. (5marks)
iii. Write a test application named EmployeeTest that demonstrates class
Employees capabilities. Create two Employee objects and display each
object’s yearly salary. (5marks)
TOTAL MARKS 20MARKS
Question 5
a) Consider the following two classes:
public class ClassA {
public void methodOne(int i) {
}
public void methodTwo(int i) {
}
public static void methodThree(int i) {
}
public static void methodFour(int i) {
}
}
public class ClassB extends ClassA {
public static void methodOne(int i) {
}
public void methodTwo(int i) {
}
public void methodThree(int i) {
}
public static void methodFour(int i) {
}
}
a. Which method overrides a method in the superclass? (1mark)
b. Which method hides a method in the superclass? (1mark)
c. What do the other methods do? (2marks)
5
b) What is the output of the following program? (6marks)
public class Animal {
public static void testClassMethod() {
System.out.println("The class method in Animal.");
}
public void testInstanceMethod() {
System.out.println("The instance method in Animal.");
}
}
//The second class, a subclass of Animal, is called Cat:
public class Cat extends Animal {
public static void testClassMethod() {
System.out.println("The class method in Cat.");
}
public void testInstanceMethod() {
System.out.println("The instance method in Cat.");
}
public static void main(String[] args) {
Cat myCat = new Cat();
Animal myAnimal = myCat;
Animal.testClassMethod();
myAnimal.testInstanceMethod();
}
}
c)
The following attempt at Java code might have been written by a beginner. Identify (but
do not correct) as many of the mistakes as you can. Explain how each oddity you identify
is either something that would prevent the program from compiling, something that
would cause it to stop abruptly reporting failure at runtime, a reason why the program
might not do anything sensible or just a stylistic oddity. (10marks)
//* A comment to start with: Exam: 2008 */
public Class mycode.java{
void static public fun main(String [junk])
begin
Leaf tr = null;
for (i=1; i>10; ++i) tr = new Node(i, tr)
tr.print();
end;
}
6
class Leaf{
integer value;
Leaf(int value){
this = value;
}
public void print(){
System.out.println(value);
}
}
class Node extends Leaf{
Leaf left, right;
Node(leaf l, Leaf r){
left = l, right = r;
}
void print(){
left.print();
System.out.println("val=" @ value);
right.print();
}
}






More Question Papers


Popular Exams



Return to Question Papers