A SECTION A: Multiple Choice Questions of Different Topics
A SECTION A: Multiple Choice Questions of Different Topics
1. Given any constructor. Which one of these statements is the appropriate answer?
(3 marks)
a) A finally block is executed before the catch block but after the try block.
1 OF 11
This assessment is subject to the University Assessment Regulations for Candidates
CS1OOP Object Oriented Programming 2020-21
4. You are writing a generic method which is going to replace all the elements that
are below a certain value with that value. Which is the most generic declaration
that you can use for it?
(3 marks)
b) public <T extends Comparable<T> > void replaceSmaller(T t, List<? super T>
l)
2 OF 11
This assessment is subject to the University Assessment Regulations for Candidates
CS1OOP Object Oriented Programming 2020-21
5. To prevent any method from overriding. How should the method be declared?
(3 marks)
a) static
b) final
c) abstract
d) constant
6. Suppose that we have the classes Animal and Bird, and Animal defines an eat()
method that Bird overrides. We have an Animal variable named "a" that points
to a Bird object. When we run "a.eat()", which version of the method gets
called?"
3 OF 11
This assessment is subject to the University Assessment Regulations for Candidates
CS1OOP Object Oriented Programming 2020-21
7. Your program needs to quickly find the student number of a Student by their
name, and you want to display all the names in alphabetical order.
a) HashMap<String, Student>
b) TreeMap<String, Student>
d) LinkedHashMap<String, Student>
a) The dynamic type is what the compiler uses to check that we are calling ap-
propriate methods and returning/passing valid values.
b) The static type of a variable is not known until we run the program.
4 OF 11
This assessment is subject to the University Assessment Regulations for Candidates
CS1OOP Object Oriented Programming 2020-21
9. We are designing a class that keeps a list of objects always sorted after each
insertion. We want to add an internal check in the class that we can enable and
disable without recompiling, which verifies that the list remains sorted and has
exactly one more element after each insertion.
c) Use assert
d) Use assertTrue
I. Packages don’t provide a mechanism to partition all class names into more
manageable chunks.
II. One of the important properties of a package is that all classes defined inside
a package is accessible by code outside that package.
III. Packages provide a visibility control mechanism.
IV. The .class files for classes declared to be part of a package can be stored in
multiple directories.
a) Only (I)
b) Only (II)
c) Only (III)
d) Only (IV)
5 OF 11
This assessment is subject to the University Assessment Regulations for Candidates
CS1OOP Object Oriented Programming 2020-21
6 OF 11
This assessment is subject to the University Assessment Regulations for Candidates
CS1OOP Object Oriented Programming 2020-21
c) Rectangle e1 = Square();
Which one of these patterns would best suit this context? (3 marks)
a) Strategy
b) State
c) Template Method
d) Decorator
7 OF 11
This assessment is subject to the University Assessment Regulations for Candidates
CS1OOP Object Oriented Programming 2020-21
What do you need to do to solve the conflict ? S ELECT ALL valid options you find.
(3 marks)
a) There is no conflict
[45 marks]
8 OF 11
This assessment is subject to the University Assessment Regulations for Candidates
CS1OOP Object Oriented Programming 2020-21
[25 marks]
9 OF 11
This assessment is subject to the University Assessment Regulations for Candidates
CS1OOP Object Oriented Programming 2020-21
a) W RITE the Java code for a skeleton of CheckAccount that fully specifies the
getSortCode, getAccountNumber and getTransactions methods but,
leave empty the getBalanceAt and drawBalanceChart methods.
(5 marks)
(3 marks)
c) W RITE a Javadoc comment for the getBalanceAt method. Make sure you
describe the parameter and the returned value, and also document how the
method may throw an IllegalArgumentException if given a null Date.
(4 marks)
[15 marks]
10 OF 11
This assessment is subject to the University Assessment Regulations for Candidates
CS1OOP Object Oriented Programming 2020-21
19. W RITE a main method that reads all the lines of a file, and then writes those
to another file in reverse order. Print appropriate error messages if a FileNot-
FoundException or an IOException is thrown.
(6 marks)
19. C OMPARE black-box and white-box testing, and EXPLAIN their differences. E X -
PLAIN how we know if we are missing tests in white-box testing.
(3 marks)
20. What is the difference between Long and long in Java? (3 marks)
(3 marks)
[15 marks]
END OF ASSESSMENT
11 OF 11
This assessment is subject to the University Assessment Regulations for Candidates