Get premium membership and access revision papers, questions with answers as well as video lessons.
Object Oriented Programming Concepts Question Paper
Object Oriented Programming Concepts
Course:Diploma In Business Information Technology
Institution: Strathmore University question papers
Exam Year:2005
1
STRATHMORE UNIVERSITY
FACULTY OF INFORMATION TECHNOLOGY
DIPLOMA IN BUSINESS INFORMATION TECHNOLOGY
DBT 1204: OBJECT ORIENTED TECHNIQUES
SUPPLEMENTARY EXAM
DATE: 13th December 2005 TIME: 2 Hours
INSTRUCTIONS
ANSWER QUESTION ONE AND ANY OTHER TWO
oo
Question 1
a. In your words, describe object oriented programming (2marks)
b. What are abstract methods? Describe the circumstances in which an abstract
method would be appropriate. (2marks)
c. Explain what is meant by the following (4marks)
i. Constructor
ii. Encapsulation
iii. Data hiding
iv. Data abstraction
d. Distinguish between the following terms
i. Subclass and superclass (2marks)
ii. Structured programming and object oriented programming
(4marks)
iii. Public and private access modifiers (2marks)
iv. Overriding and overloading (2marks)
v. Object and Class (2marks)
Question 2
a. Create a class called invoice that a hardware store might use to represent an
invoice for an item sold at the store. An invoice should include 4 pieces of
2
information as instance variables; a part number (type string), a part description
(type string), a quantity of the item being purchased (type int) and a price per item
(double). (5marks)
b. Your class should have a constructor that initializes the 4 instance variables.
Provide a set and a get method for each of the 4 instance variables. In addition
provide a method named getInvoiceAmount that calculates the invoice amount i.e.
multiplies the quantity by the price per item, then returns the amount as a double
value. If the quantity is not positive, it should be set to 0.0. (5marks)
c. Write a test application named invoiceTest that demonstrates class invoice’s
capabilities. (5marks)
d. Imagine you are given the task of designing a sales tracking system for a fast food
restaurant. The system keeps track of all menu items offered by the restaurant and
the number of daily sales per menu item. 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. (5marks)
Question 3
a. Discuss the ways in which inheritance promotes software reuse, saves time during
program development and helps prevent errors. (3marks)
b. What will be the output from the following code? (8marks)
class Q2Main{
public static void main(String args[]){
QuestionTwo q2;
q2=new QuestionTwo();
q2.init();
q2.increment();
q2.increment();
System.out.println(q2.getCount());
}
}
class QuestionTwo{
private int count;
public void init(){
3
count=1;
}
public void increment(){
count=count+1;
}
public int getCount(){
return count;
}
}
c. What are some of the costs of using inheritance for software development?
(3marks)
d. What is the name of the root class for all objects in java? (1mark)
e. Why would it not make sense in Java for a method to be declared as both abstract
and final? (2marks)
f. Why would you say the example used in the following illustration not a valid
illustration of inheritance?
“Perhaps the most powerful concept in OOP systems is inheritance. Objects can
be created by inheriting the properties of other objects, thus removing the need to
write any code whatsoever! Suppose, for example, a program is to process
complex numbers consisting of real and imaginary parts. In a complex number,
the real and imaginary parts behave like real numbers so all of the operations (+,-
,/,*, sqrt, sin, cos, etc) can be inherited from the class of objects called REAL,
instead of having to be written in code. This has a major impact on programmer
productivity. ”
(3marks)
Question 4
a. Consider this class
public class Account{
private double balance;//instance variable that stores balance
//constructor
public Account(double initialBalance){
//validate that initial balance is greater than 0.0
//if it is not, balance is initialized to the default
//value 0.0
4
if(initialBalance>0.0)
balance=initialBalance;
}//end constructor
//credit (add) an amount to the account
public void credit(double amount){
balance=balance+amount;//add amt to balance
}
//return the account balance
public double getBalance(){
return balance;
}
}
Modify the class Account to provide a method called debit that withdraws money
from an account. Ensure that the debit amount does not exceed the Account’s
balance. If it does, the balance should be left unchanged and the method should
print a message indicating “Debit amount exceeded account balance” (10marks)
b. In a problem domain of your choice, show the use of USE CASE
DIAGRAMS in modeling system functional requirements. (10marks)
Question 5
a. Explain the role of the following as used in Object Oriented Analysis and
Design (12marks)
i. UML
ii. Class Diagram
iii. Use Case Diagram
iv. Sequence Diagram
v. Collaboration Diagram
vi. State Diagram
b. Consider the following class definitions. Identify which calls to the
constructor are invalid. (8 marks)
class Car{
5
public String make;
protected int weight;
private String color;
private Car(String make, int weight, String color){
this.make=make;
this.weight=weight;
this.color=color;
}
public Car(){
this("unknown", -1, "white");
}
}
class ElectricCar extends Car{
private int rechargeHour;
public ElectricCar(){
this(10);
}
private ElectricCar(int charge){
super();
rechargeHour=charge;
}
}
class TestMain{
public static void main(String args[]){
Car myCar1,myCar2;
ElectricCar myElec1,myElec2;
myCar1=new Car();
myCar2=new Car("Ford",1200,"Green");
myElec1=new ElectricCar();
myElec2=new ElectricCar(15);
}
}
More Question Papers