Exam 2017, questions PDF

Title Exam 2017, questions
Course Object-Oriented Programming
Institution University of Essex
Pages 15
File Size 334.9 KB
File Type PDF
Total Downloads 55
Total Views 140

Summary

Summer Exam 2017 Questions...


Description

CE152-4-SP UNIVERSITY OF ESSEX Undergraduate Examinations 2017

OBJECT-ORIENTED PROGRAMMING

Time allowed: TWO hours

The following items are provided: OMR Form for answering multiple-choice questions Graph paper (available on invigilator’s desk)

The paper consists of TWENTY-EIGHT questions – TWENTY-FIVE questions in SECTION A and THREE questions in SECTION B.

Candidates must answer ALL QUESTIONS in SECTION A on the machine-readable form and ALL QUESTIONS in SECTION B in the answer booklet provided.

Questions are NOT of equal weight.

The percentages shown in brackets provide an indication of the proportion of the total marks for the PAPER which will be allocated.

THE QUESTION PAPER MUST NOT BE REMOVED AND WILL BE COLLECTED WITH YOUR ANSWER SHEET. Please do not leave your seat unless you are given permission by an invigilator. Do not communicate in any way with any other candidate in the examination room. Do not open the question paper until told to do so. All answers must be written in the answer book(s) provided. All rough work must be written in the answer book(s) provided. A line should be drawn through any rough work to indicate to the examiner that it is not part of the work to be marked. At the end of the examination, remain seated until your answer book(s) have been collected and you have been told you may leave.

2

CE152-4-SP

SECTION A Candidates must answer ALL questions. Answers to Section A must be written on the multiple choice answer sheet (machinereadable form). Note that there is only one choice that constitutes the correct answer to each question. The correct answer, in this context, is the most accurate and complete answer to the question, among those given.

Question 1

[2%]

Which of the following is NOT a Java keyword? [A]

object

[B]

new

[C]

package

[D]

static

Question 2

[2%]

What output will be produced by the following Java program fragment? boolean a = true; boolean b = false; a = a || b; b = a && ! b; System.out.println(a + " " + b);

[A]

false false

[B]

false true

[C]

true false

[D]

true true

3

Question 3

CE152-4-SP

[2%]

What output will be produced by the following Java statement? System.out.println("Result = " + 1 + 2*3);

[A]

Result= 7

[B]

Result= 16

[C]

Result= 12*3

[D]

Result= 1222

Question 4

[2%]

What output will be produced by the following Java program fragment? int a = 8; int b = 2; while (a > 0) { a -= b; if (a == 3) continue; else b++; } System.out.println(a + b);

[A]

3

[B]

4

[C]

5

[D]

6

CE152-4-SP

4

Question 5

[2%]

In a Java program, suppose that a certain entity has the name MESSAGE. Assuming standard Java naming conventions, what kind of entity is this most likely? [A]

A constant

[B]

A class

[C]

A local variable with a changing value

[D]

A package

Question 6 What output will be produced by the following Java program fragment? String x = "abcdef"; for (int i = 0; i < x.length(); i = i + 2) { String c = x.substring(i, i + 1); if (!"aeiou".contains(c)) System.out.print(c); }

[A]

c

[B]

ae

[C]

bcdf

[D]

abcdef

[2%]

5 Question 7

CE152-4-SP [2%]

A programmer has written a method that takes as its argument an array of integers and returns a new array with the same elements but in reverse order. Unfortunately, one of the lines in the program has gone missing: public static int[] revIntArray(int[] array) { int[] result = new int[array.length]; // MISSING A LINE HERE for (int a : array) { result[index] = a; index-= 1; } return result; }

Which of the following lines should be inserted so that the method works correctly? [A]

int index = 0

[B]

int index = 1

[C]

int index = array.length – 1;

[D]

int index = array.length;

Question 8

[2%]

What output will be produced by the following Java program fragment? int[][] alpha = {{1},{2,3}}; int[] beta = {4,5,6}; alpha[0] = beta; System.out.println(alpha[0][0] + alpha[1][1]);

[A]

4

[B]

5

[C]

6

[D]

7

6

CE152-4-SP

Question 9

[2%]

Consider the following Java program public class MainTest { public static void main(String[] args) { Integer n = Integer.parseInt(args[0]); if (n > 0) { System.out.print(n); args[0] = "" + (n - 1); main(args); } } }

Which of the following statements is TRUE? [A]

The program does not compile because of an illegal invocation of method main.

[B]

When the program is run without a command line argument, it will exit without displaying a message or throwing an exception.

[C]

When the program is run with the command line argument 0, it will exit without displaying a message or throwing an exception.

[D]

When the program is run with the command line argument 3, the console will display the message 3210

Question 10 Which of the following is NOT a java.util.Scanner method? [A]

nextInt

[B]

hasNext

[C]

nextLine

[D]

nextString

[2%]

7

Question 11

CE152-4-SP

[2%]

In Java, which of the following is the “standard” input stream? [A]

System.console

[B]

System.in

[C]

System.input

[D]

System.stdio

Question 12

[2%]

During a Java program run, what happens when the JVM tries to open an input file that does not exist? [A]

The JVM will throw a FileNotFoundException

[B]

The JVM will treat it as if it was an empty input file.

[C]

The JVM will skip over all further program statements relating to this file.

[D]

The JVM will terminate the program without throwing an exception.

Question 13

[2%]

In the context of Java programming, which of the following statements is FALSE? [A]

The name of a constructor is the same as the class name.

[B]

Two variables can refer to the same object.

[C]

A class can have several constructors.

[D]

In a constructor, the parameter names must be different from the field names of the class.

CE152-4-SP

8

Question 14

[2%]

Which of the following statements about Java access levels is FALSE? [A]

A private method can access a public field of another class.

[B]

A private method can only be accessed in its own class.

[C]

A private data field can be read but not modified from outside the class.

[D]

A method without explicit access level is visible from the same package.

Question 15

[2%]

In the Java API, the interface Comparable has a compareTo() method. What is the type of this method? [A]

int compareTo()

[B]

int compareTo(Object o)

[C]

int compareTo(T o)

[D]

int compareTo(Comparable o)

Question 16

[2%]

Consider the following statements about interfaces in Java: o Interfaces method names must be different from class method names so as to avoid a name clash. o Each class must implement at least one interface. [A]

Both statements are true.

[B]

The first statement is true; the second is false.

[C]

The first statement is false; the second is true.

[D]

Both statements are false.

9

Question 17

CE152-4-SP

[2%]

What output will be produced by the following Java program fragment? List x = new ArrayList(); for (int i = 0; i < 5; i++) x.add(2*i); x.remove(4); System.out.println(x);

[A]

[]

[B]

[8]

[C]

[0, 2, 4, 6]

[D]

[0, 2, 6, 8]

Question 18 Which of the following statements about Java class Object is TRUE? [A]

It is a subclass of all other Java classes

[B]

It is the only class which has no parent class

[C]

It has a toString method which prints the name and value of all fields.

[D]

It has an equals method which compares objects by the value of their fields.

[2%]

CE152-4-SP

10

Question 19

[2%]

What output will be produced by the following Java program fragment? Integer x = new Integer(4); Integer y = new Integer(5); x = y; y = x; System.out.println(x.equals(y) + " " + (x == y));

[A]

false false

[B]

false true

[C]

true false

[D]

true true

Question 20 Which of the following statements about abstract classes in Java is TRUE? [A]

All methods in an abstract class must be abstract.

[B]

Abstract classes can have a constructor.

[C]

Abstract classes cannot implement interfaces.

[D]

All fields in an abstract class must be abstract.

[2%]

11

Question 21

CE152-4-SP

[2%]

What output is produced if the following source code is compiled and run? public class A { public int number = 1; public A() { number *= 2; } public static void main(String[] args) { B b = new B(); System.out.println(b.number); } } class B extends A { public B() { number += 1; } }

[A]

1

[B]

2

[C]

3

[D]

4

Question 22

[2%]

Which of the following statements about Java Swing is TRUE? [A]

A BorderLayout distinguishes five regions: LEFT, RIGHT, TOP, BOTTOM and MIDDLE

[B]

A JPanel has a title field.

[C]

The default JFrame layout is GridLayout

[D]

A JFrame is a top-level container.

12

CE152-4-SP

Question 23

[2%]

In the Java Swing API, which of the following is an interface? [A]

ActionEvent

[B]

ActionListener

[C]

JButton

[D]

MouseAdapter

Question 24

[2%]

Which of the following statements about the classical Quicksort algorithm is FALSE? [A]

It works by partitioning the array into three parts, then sorting each part one after another.

[B]

It is a “divide-and-conquer” algorithm.

[C]

During the "portioning step", it compares elements with a "pivot" element.

[D]

It is a recursive algorithm.

Question 25

[2%]

Which of the following is an annotation for Junit test methods? [A]

@Equals

[B]

@Test

[C]

@True

[D]

@False

END OF SECTION A

13

CE152-4-SP

SECTION B

Candidates must answer ALL questions in SECTION B in the answer book provided.

Question 26 A programmer has been asked to write a method powersOfTwoArray(n) which should return an array containing the powers of 2 from 20 up to and including 2n, where n is an integer that is supplied as an argument. For example, if n=4, then the method should return an array containing the numbers [1, 2, 4, 8, 16]. You can assume that the integer n supplied is non-negative and that it is less-or-equal to 30. The programmer has written the method below. The numbers on the left are line numbers; they are not part of the code. 1 2 3 4 5 6 7 8 9 10

public static int[] powersOfTwoArray(int n) { int[] result = new int[n]; int i = 0; int power = 0; while (i 0) { A x = xs.get(0); xs.remove(0); xs.add(x); myFun(xs,n-1); } }

(a)

Briefly explain the meaning of the notation in the declaration of method myFun.

[2%]

(b)

Method myFun is recursive. Briefly explain what this means.

[2%]

(c)

Does the recursive method myFun always terminate or is it possible that it would go into an infinite recursion? Give reasons for your answer.

[3%]

(d)

Describe the output produced by method testMyFun.

[3%]

END OF SECTION B

END OF EXAM PAPER CE152-4-SP...


Similar Free PDFs