Computer Laboratory


Supervision questions: Object Oriented Programming

This is the set of questions for my supervisions in Object Oriented Programming. I will typically email you a list of question numbers before each supervision, but if not, attempt the next two or three. (More questions will appear here as I set them, so come back if you want to make an early start on some of the future work.)

Administrativa & handing in work

I expect you to make a good attempt at producing solutions to the relevant questions before each supervision. I prefer submissions by email (PDF or text format). Please submit your work 24 hours before the supervision. If you want to submit a hard copy of the work to student administration, please hand it in before 17:00 two days before the supervision (i.e. before Wednesday, 17:00 for a Friday afternoon supervision) as I will have to scan it. Remember that Student Administration is closed on weekends.

When emailing me regarding supervisions, please only use my lab address, or your email will be misfiled and may slip by unnoticed:

The mark allocation (whilst very approximate) should give you a rough idea of how you should divide your time between the questions, as well as how much credit I expect a similar question to be worth in the exam. It will also serve as a guide for me when marking the questions.

If there is a particular part of the course you would like explaining, or questions you have about the lectures (independent of whether they are covered by the questions or not), please let me know in an email before the supervision so that I can prepare appropriately.

Supervision 1: Fundamentals

  1. In the context of functional and imperative programming, what is the difference between a function and a procedure? Which is used with which programming methodology? [4 marks]
  2. Explain in a short (max. a couple of paragraphs) high-level description of how a computer can execute a program written in some imperative programming language. Your answer should mention the following terms:
    • memory address,
    • compilation (or compile, compiler etc.),
    • main (system) memory,
    • registers,
    • transistors / logic gates.
    • fetch-execute cycle,
    [8 marks]
  3. Q1 from the example sheet [3 marks]
  4. Q2 from the example sheet [8 marks]
  5. Explain briefly the concept of Java bytecode and how the process described in 2. changes if we are considering a Java program. [Hint: There is one additional step that has to be performed]. [3 marks]
  6. What might a pointer type of int **p in the C language mean? Explain how you would get at the int value stored. [2 marks]
  7. Q3 from the example sheet [4 marks]
  8. Q4 from the example sheet [5 marks]
  9. Explain the difference between passing something "by reference" and "by value". Assuming a class Int with a member field value, write a small piece of code that contrasts the behaviour of this with the primitive int type. [Hint: Consider passing them to a procedure that will change the value, and what value they will hold after the procedure has returned]. [5 marks]
  10. 1999 Paper 3 Question 3, first part only [15 marks]

Supervision 2: OOP Principles, Java

  1. 2009 Paper 1 Question 8, part (a) only [6 marks]
  2. Explain the terms coupling and cohesion, and indicate what we are generally optimising for with each of them ("low"/"high"). [4 marks]
  3. Q5 from the exercise sheet [6 marks]
  4. Explain the differences between a class, an abstract class and an interface [6 marks]
  5. Q24 from the exercise sheet [7 marks]
  6. Explain what polymorphism is in the context of object-oriented programming languages and how its realisation differs between Java and C++. [Hint: Use a worked example and consider virtual functions in the case of C++]. [5 marks]
  7. Give an example of variable shadowing as a result of inheritance. [3 marks]
  8. Modify the Vector2D class from lectures to handle subtraction and scalar product. [12 marks]
  9. Is the Vector2D class developed in lectures mutable or immutable? [2 marks]
  10. What is the difference between shallow and deep copying when cloning an object (using the clone() keyword or otherwise). [6 marks]
  11. Q10 from the exercise sheet [8 marks]
  12. Q13 from the exercise sheet [5 marks]
  13. Bonus question: Explain how to write a Java program that is ‘functional’ in nature i.e. no modifiable variables, methods are mathematical functions without side effects. Remember the final keyword. [8 marks]

Supervision 3: Class Library, Design Patterns

Please also note the Java Programming Competition page!
  1. What is the Java class library? In the context of the class library, explain what a collection and a comparator are and why they are useful. What are examples of each? [4 marks]
  2. What are generics in Java? Why were they introduced? [Hint: Think about early versions of the collections framework] [4 marks]
  3. Write an implementation of a generic linked list, i.e. one that can hold any type of object, using Java generics (cf. Q30 on the exercise sheet). [5 marks]
  4. Is there a difference between the == operator and calling the .equals() method on an object, and if so, when? [2 marks]
  5. Q37 from the exercise sheet [8 marks]
  6. What is a design pattern? [1 mark]
  7. Q41 from example sheet [5 marks]
  8. What is the difference between the state and strategy patterns? [3 marks]
  9. Q42 from the example sheet [12 marks]
  10. Q43 from the example sheet [4 marks]
  11. Draw the diagram for and explain the abstract factory pattern. Thensketch a solution to Q45 on the example sheet by re-labeling the components of your diagram with their correspondences in this example (e.g. using a different colour). [8 marks]
  12. Without referring to the solution notes, do the second question of the sample exam questions. You may skip the differences between abstract classes and interfaces in part (a) [18 marks]
  13. 2009 Paper 1 Question 8, part (b) [14 marks]