0% found this document useful (0 votes)
24 views5 pages

SPE 2207 Advanced Object-Oriented Programming Year II Semester II

Uploaded by

nyakundip11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views5 pages

SPE 2207 Advanced Object-Oriented Programming Year II Semester II

Uploaded by

nyakundip11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

UNIVERSITY EXAMINATION 2021/2022

EXAMINATION FOR THE DEGREE OF BACHELOR OF SCIENCE IN


SOFTWARE ENGINEERING

SPE 2207 Advanced Object-Oriented Programming Year II Semester II


Date: Wednesday 15th June 2022 Time: 1.30 pm – 3.30 pm
Instructions: Answer question one and any other two questions

QUESTION ONE (30 marks)


a. A company needs to move its stock information into a database to allow concurrent stock
queries and purchase updates by many customers over the web.
i. If concurrent transactions by multiple users are interleaved without concurrency
control, outline four problems that could occur (4 marks)
ii. The company programmer wants to execute a query in JDBC for their new branch.
Describe the steps required to execute the query (4 marks)
b. Using java create an object called "myCar" with two attributes x and y:
and print the value of x: (4 marks)
c. Write a java code to demonstrate the “Car class (in b above) should inherit
the attributes and methods from “Vehicle class”. (3 marks)
d. Assuming that you have a bird class and are creating a list of birds, demonstrate
how inheritance implemented in java (4 marks)
e. Write a code fragment that demonstrates how the open-closed principle of
object-oriented programming may be implemented in practice. (4 marks)
f. Use the following code to answer the questions that follows
public class Demo{
public static void main(String[] arr){
System.out.println(“Main1”);
}
public static void main(String arr){
System.out.println(“Main2”);
}
i. Provide the output of the above code (3 marks)
ii. Using the code explain how the problem of overload in the main()
method will be resolved (4 marks)

QUESTION TWO (20 marks)


a. Create a Car object named myCar. Call the fullThrottle() and speed() methods on
the myCar object, and run the program: (5 marks)
b. Describe five properties contained by each Java thread (5 marks)

Page 1 of 3
Page 1 of 5
c. Using examples explain what method overloading is and explain how it differs from
method overriding. (4 marks)
d. Using a Java code example illustrates three situations in which abstract classes are
commonly used. (6 marks)

QUESTION THREE (20 marks)

Use the below code to answer the questions that follow


public class Single {
public static int total= 0;
private int xCoord;
public Single(int x){xCoord= x; total= total+1;} // Constructor
// returns true if and only if the xCoords fields of s
// and the current Single are the same.
public boolean equals(Single s) {return (s.xCoord == this.xCoord);}
public int hashCode(){return xCoord;};
public String toString() {return ""+ xCoord;}
}
class Pair extends Single{ // A Pair is a pair of integers of the form (xCoord, yCoord)
int yCoord;
public Pair(int x, int y){
xCoord= x;
yCoord= y;
}
// returns true if and only if the sum of the two coordinate fields
// (i.e. xCoord + yCoord) of p is the same as that of the current Pair.
public boolean equals(Pair p){
return (this.xCoord+ this.yCoord == p.xCoord+ p.yCoord);
}
class Test {
public static void main(String args[]){
Single s= new Single(2); // Line 1
Pair first= new Pair(1,4); // Line 2
System.out.println("There are " + Single.total + " Singles"); // Line 3
Single second= new Pair(2, 3); // Line 4
Pair third= new Pair(4, 1); // Line 5
System.out.println("Is second equal to first?" + first.equals(second)); // Line 6
System.out.println("Is second equal to first?" + first.equals((Pair) second)); // Line 7
}}

a. What is the function of the private and public keywords? (4 marks)


b. Currently the class definitions above would not compile. Explain why not and
suggest a modification of the code which would correct that problem. (4 marks)
c. Briefly explain what a class variable is, referring to the class Single above to provide
illustrations of your explanation. (6 marks)
d. Assuming that the code is corrected so that it compiles and runs, what is the output at
Line 6 and at Line 7? Explain your answer. (6 marks)

Page 2 of 3
Page 2 of 5
QUESTION FOUR (20 MARKS)

a. Explain two role of condition variables when writing a class that manages a shareable
resource. (4 marks)
b. Explain three reasons why the use of static and instance variables in a class definition
becomes complex when writing methods that support concurrent access for threads.
(6 marks)
c. With reference to message passing concurrent implementations explain the difference
between channel-based systems and actor-based systems. (6 marks)
d. Provide code snipet that will indicate how to call a Stored Procedure from Java
Database connectivity. (4 marks)

QUESTION FIVE (20 MARKS)

a. Using a java program illustrate the concept of function overloading. (5 marks)


b. Write a java program that implements a loop to display all multiples of 7 between
1 and 100 (5 marks)
c. Explain four reasons why Object-Oriented programming languages provide support
for concurrency. (4 marks)
d. Describe three problems the designer of java tries to avoid when they only list
a single parent class after the extends keyword in a class declaration. (6 marks)

Page 3 of 3

Page 3 of 5
Page 4 of 5
Page 5 of 5

You might also like