FinalExam2020 Name Id GroupNumber
FinalExam2020 Name Id GroupNumber
FinalExam2020 Name Id GroupNumber
FINAL EXAMINATION
Object Oriented Programming
Spring 2020
Name:……………………………………………………………………………………………… ID#:…………………………………………………………… Group#:……………….
Instructions:
There are 20 points possible on this test.
This is a OPEN book exam.
Quickly browse each problem before beginning the test. Note that some
questions are worth more points than others.
The answers must be in English.
The exam consists of the following parts:
Part A: Basic OOP questions worth 5 points.
Part B: UML coding questions worth 5 points
Part C: Exception handling & generic programming questions worth 5
points
Part D: Putting things together problem set worth 5 points
The time limit for the exam is 120 minutes.
Part Questions Max Points Score
1 2.5
A
2 2.5
1 5
B
1 2.5
C
2 2.5
D 1 5
Total: _____________________/20
1
Part A: Basic Questions. [5 marks]
1. For each of the following questions about Java, circle T (true) or F (false).
[2.5 marks]
a. T F Both interfaces and classes define the type system in Java.
b. T F Java supports multiple inheritance for classes but only single inheritance for
interfaces
c. T F A type (class of interface) in Java can have more than one subtypes.
d. T F An abstract class cannot contain any method implementations.
e. T F In class inheritance, a subclass inherits only the nonprivate members of the
superclass.
f. T F The class java.lang.Object is the only class, standard or programmer-defined,
that has no superclass.
g. T F A program that throws an uncaught exception generates a compile-time rather
than a run-time error.
h. T F the following program will fail to compile
public final class Algorithm {
public static <T> T max(T x, T y) {
return x > y ? x : y;
}
}
i. T F The Vector class is a kind of generic programming implementation.
j. T F The question mark (?) is known as the wildcard in generic programming. It
represents an unknown type.
2. Write next to each method call in “main()” the output that it prints. [2.5 marks]
class A {
2
public class TypeMeister {
A a = new A();
B b = new B();
A ba= b;
3
b) Write a Java version of class Member assuming it has this constructor:
public Member(String name, String address) and that the method
getFee() is abstract. [1 marks]
4
public Society(String societyName) [1 marks]
if (b==0)
throw new IllegalArgumentException(“cannot divide by 0”);
return a / b;
}
Change this method so that it catches the IllegalArgumentException thrown by divide and
prints the message “the divisor is zero” if it is thrown. [1.5 marks]
System.out.println(divide(a, b));
}
2. Select the right output of the following codes:
Code1:
import java.util.*;
public class genericstack <E>
{
Stack <E> stk = new Stack <E>();
public void push(E obj)
{
stk.push(obj);
}
public E pop()
{
E obj = stk.pop();
return obj;
5
}
}
class Output
{
public static void main(String args[])
{
genericstack <String> gs = new genericstack<String>();
gs.push("Hello");
System.out.println(gs.pop());
}
}
Code 3:
import java.util.*;
public class genericstack <E>
{
Stack <E> stk = new Stack <E>();
public void push(E obj)
{
stk.push(obj);
}
public E pop()
{
E obj = stk.pop();
return obj;
}
}
class Output
{
public static void main(String args[])
{
genericstack <Integer> gs = new genericstack<Integer>();
gs.push(36);
System.out.println(gs.pop());
}
6
}
7
Good Luck