CS1027midtermSolutions2009.doc

48 views14 pages
Page:
of 14
The University of Western Ontario
Department of Computer Science
Computer Science 1027b Midterm Exam
With Solutions
Print your name:______________________________________________
Student number: ______________________________________________
Instructions:
Fill in your name and student number above immediately.
Answer all the questions in the exam in the spaces provided.
You have 2 hours to complete the exam.
The exam has 8 questions on 14 pages, and is out of a possible 80 marks.
The marks for each individual question are given. Allow approximately 1.5 minute
per mark on average.
There is a page for rough work at the end of the exam paper.
Read the questions carefully!
DO NOT TURN THIS PAGE UNTIL DIRECTED TO DO SO.
1 (max 15)
2 (max 5)
3 (max 10)
4 (max 15)
5 (max 10)
6 (max 10)
7 (max 10)
8 (max 5)
TOTAL
(max 80)
1. (15 marks) True/False (Circle your answers) (Answers are italicized)
a) (1 mark) A static method within a class can be invoked without having to instantiate an
object of that class.
True False
b) (1 mark) A Java interface should never contain a constructor.
True False
c) (1 mark) A Java interface never contains an attribute (instance variable) declaration.
True False
d) (1 mark) A new class X derived from a class Y establishes an is-a relationship from
class X to class Y.
True False
e) (1 mark) All Java classes are derived, directly or indirectly from the Object class
True False
f) (1 mark) Any method in a Java class X can call public and private methods from X.
True False
g) (1 mark) In the Java statement
LinkedBag<BingoBall> b = new LinkedBag<BingoBall>( );
BingoBall is a generic type.
True False
2
h) (1 mark) The reserved word super can be used in a class to refer to its parent class.
True False
i) (1 mark) The objects in a Java program are created when the program is being
executed, as opposed to when it is compiled.
True False
j) (1 mark) The terms parent class, superclass, and base class all mean the same thing.
True False
k) (1 mark) The code in ArrayBag.java is an implementation of the BagADT interface.
True False
l) (1 mark) A child class cannot override a parent method that is declared as final.
True False
m) (1 mark) Executable code is generally found in interfaces.
True False
n) (1 mark) The file BagADT.java contains both an interface and an implementation
of it.
True False
o) (1 mark) The methods enqueue(), dequeue(), first(), size(), and isEmpty() from
the class LinkedQueue have time complexity O(1).
True False
3