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:2009



1
STRATHMORE UNIVERSITY
FACULTY OF INFORMATION TECHNOLOGY
Diploma in Business Information Technology
DBT 2101: OBJECT ORIENTED PROGRAMMING CONCEPTS
DATE: 14th April 2009 TIME: 2 Hours
INSTRUCTIONS
ANSWER QUESTION ONE AND ANY OTHER TWO QUESTIONS. ALL QUESTIONS
CARRY EQUAL MARKS

Question 1
a) Write a Java statement to display the message ‘I Love Java’ in the console
window (3 marks)
b) Which of the following constructors are invalid? (2 marks)
public int ClassA (int one) {

}
public ClassB (int one, int two) {

}
void ClassC () {

}
c) What is object-oriented programming? How is it different from the procedureoriented
programming? (4marks).
d) Distinguish between the following terms (6 marks)
1) Objects and classes
2) Data abstraction and data encapsulation
3) Inheritance and polymorphism
2
e) Consider the following class declaration. (5 marks)
class QuestionOne {
public final int A=345;
public int b;
private float c;
private void methodOne (int a) {
b=a;
}
public float methodTwo () {
return 23;
}
}
Identify invalid statements in the following main class. For each invalid
statement, state why it is invalid.
class Q1Main {
public static void main (String args []) {
QuestionOne q1;
q1=new QuestionOne ();
q1.A=12;
q1.b=12;
q1.c=12;
q1.methodOne (12);
q1.methodOne ();
System.out.println (q1.methodTwo (12)); take in argument
q1.c=q1. methodTwo ();
}
}
TOTAL MARKS 20


Question 2
a) What would be the output of the following code? (5 marks)
class Q2Main {
public static void main (String args []) {
QuestionTwo q2;
q2.init ();
q2.increment ();
q2.increment ();
System.out.println (q2.getCount ());
}
}
class QuestionTwo {
private int count;
public void init () {
count = 1;
}
public void increment () {
count = count + 1;
}
public int getCount () {
return count;
}
}
b) Which is the subclass and which is the superclass in the declaration below?
(2 marks)
Class X extends Y
c) Which visibility modifier allows the data members of a superclass to be accessible
to the instance of subclass? (2 marks)
d) If X is a private member of the superclass, is X accessible from a subclass of
super? (2marks)
e) If X is a protected member of the super class, is X of one instance accessible from
another instance of super? What about from the instances of a subclass of super?
(3 marks)
f) How do you call the super class’s constructor from its subclass? What statement
will be added to a constructor of a subclass if it is not included in the constructor
explicitly defined by the program? (3 marks)
g) Can you create an instance of an abstract class? Must an abstract class include an
abstract method? (2 marks)
4
h) What is wrong with the following declaration? (1 marks)
class vehicle {
abstract public getVIN ();

}
TOTAL MARKS 20

Question 3
a) Draw a class diagram summarizing the following facts about a library.
For each book held by the library, the catalogue contains the title, author's name
and ISBN of the book. There may be multiple copies of a book in the library.
Each copy of a book has a unique accession number. There are many registered
readers belonging to the library, each of whom is issued with a number of tickets.
The system records the name and address of each reader, and the number of
tickets that they have been issued with. Readers can borrow one book for each
ticket that they possess, and the system keeps a record of which books a reader
has borrowed, along with the date that the book must be returned by.
(10 marks)
b) In the library described above, readers can borrow, return and renew books from
the library by forwarding a ticket to the library staff at the library desk. Readers
have an option of purchasing additional tickets from the library. Any book that is
not returned by the due date is subject to a fine of $1 per day. Library staff is
responsible for collecting fines, adding new books to the library. Draw a use-case
diagram for the library.
(10 marks)
TOTAL MARKS 20
5

Question 4
a) Consider the class definition below
public class Account {
private double balance;
public Account (double initialBalance) {
if (initialBalance>0.0)
balance=initialBalance;
}
public void credit (double amount) {
balance=balance + amount;
}
public double getBalance () {
return balance;
}
}
Modify the class to provide a method called debit that withdraws money from the
Account. Ensure the debit amount does not exceed the Account balance. If it does,
the balance should be left unchanged and the method should print a message
indicating “Debit amount exceeded account balance” (5 marks)
b) Why would it not make sense in Java for a method to be declared as both abstract
and final? (3 marks)
c) What is the output of the following demonstration? (5 marks)
class MultiDimArrayDemo {
public static void main (String [] args) {
String [] [] names = {{"Mr. ", "Mrs. ", "Ms. "},
{"Smith", "Jones"}};
System.out.println (names [0] [0] + names [1] [0]);
System.out.println (names [0] [2] + names [1] [1]);
}
}
6
f) Complete the following constructor. (2 marks)
class Test {
private double score;
public Test (double val) {
//assign the value of parameter to
//the data member
}
}
g) How is a local variable different from an instance variable? Rewrite the following
method using local variables. (5 marks)
public int totalCharge (int amt) {
return (balance – (int) Math. round (amt * 1.5))
}
TOTAL MARKS 20

Question 5
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
information as instance variables: a part number (type string), a part description
(type string), quantity of the item being purchased (type int) and a price per item
(double). (5 marks)
b) Provide a constructor that initializes the 4 instance variables. Also provide a set
and 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. (5 marks)
c) Write a test application named invoiceTest that demonstrates class invoice’s
capabilities. (5 marks)
7
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 as system. Describe the data values and methods you
would associate with each class you identify. (5 marks)
TOTAL MARKS 20






More Question Papers


Popular Exams


Mid Term Exams

End Term 1 Exams

End Term 3 Exams

Opener Exams

Full Set Exams



Return to Question Papers