Multiple Choice Questions (20 points)

Similar documents
Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Java Interview Questions and Answers

Part I. Multiple Choice Questions (2 points each):

Introduction to Java

C++FA 5.1 PRACTICE MID-TERM EXAM

Lecture Notes on Linear Search

J a v a Quiz (Unit 3, Test 0 Practice)

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution

1. Use the class definition above to circle and identify the parts of code from the list given in parts a j.

Programming with Data Structures

C++ Overloading, Constructors, Assignment operator

IS0020 Program Design and Software Tools Midterm, Feb 24, Instruction

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

Sample CSE8A midterm Multiple Choice (circle one)

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

CSE140: Midterm 1 Solution and Rubric

C++ INTERVIEW QUESTIONS

Data Structures. Algorithm Performance and Big O Analysis

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; }

AP Computer Science Java Mr. Clausen Program 9A, 9B

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction

Section IV.1: Recursive Algorithms and Recursion Trees

JAVA - METHODS. Method definition consists of a method header and a method body. The same is shown below:

Recursion and Recursive Backtracking

Chapter 13 - Inheritance

SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI-89. by Joseph Collison

Moving from CS 61A Scheme to CS 61B Java

History OOP languages Year Language 1967 Simula Smalltalk

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Solving Problems Recursively

Data Structures and Algorithms Written Examination

Software Engineering Concepts: Testing. Pointers & Dynamic Allocation. CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009

Pseudo code Tutorial and Exercises Teacher s Version

C H A P T E R Regular Expressions regular expression

The Interface Concept

Introduction to Python

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. CSC467 Compilers and Interpreters Fall Semester, 2005

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Two-Dimensional Arrays. Multi-dimensional Arrays. Two-Dimensional Array Indexing

1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright /6/11 12:33 PM!

Chapter 5 Functions. Introducing Functions

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

Recursion. Slides. Programming in C++ Computer Science Dept Va Tech Aug., Barnette ND, McQuain WD

Statements and Control Flow

Python for Rookies. Example Examination Paper

Matrix Algebra. Some Basic Matrix Laws. Before reading the text or the following notes glance at the following list of basic matrix algebra laws.

The C Programming Language course syllabus associate level

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION

Common Beginner C++ Programming Mistakes

Programming Language Features (cont.) CMSC 330: Organization of Programming Languages. Parameter Passing in OCaml. Call-by-Value

Object-Oriented Programming in Java

C++FA 3.1 OPTIMIZING C++

Sources: On the Web: Slides will be available on:

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing

Algorithms and Data Structures Written Exam Proposed SOLUTION

Object Oriented Software Design

Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014!

Regular Expressions and Automata using Haskell

Online EFFECTIVE AS OF JANUARY 2013

Curriculum Map. Discipline: Computer Science Course: C++

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Properties of Real Numbers

What Is Recursion? Recursion. Binary search example postponed to end of lecture

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions

13 Classes & Objects with Constructors/Destructors

An Incomplete C++ Primer. University of Wyoming MA 5310

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Introduction: Abstract Data Types and Java Review

CmpSci 187: Programming with Data Structures Spring 2015

LAB4 Making Classes and Objects

Stack Allocation. Run-Time Data Structures. Static Structures

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Object Oriented Software Design

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Test #4 November 20, True or False (2 points each)

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Crash Course in Java

Computer Programming I

PostgreSQL Functions By Example

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Computer Science 210: Data Structures. Searching

So let us begin our quest to find the holy grail of real analysis.

Transcription:

CSC142 Midterm 2 1 Multiple Choice Questions (20 points) Answer all of the following questions. READ EACH QUESTION CAREFULLY. Fill the correct bubble on your scantron sheet. Each correct answer is worth 1 point. Each question has EXACTLY one correct answer. 1. Consider the following method: public int foo(int[] a, int m) int j; for(j=0; j<a.length; j++) if (a[j]==m) break; return j; What can you say for sure about foo? A. foo always returns the index of the array element equal to m B. foo always returns the length of the array C. foo must be used with care. It crashes if a is an array of zero length. D. If m is in the array, foo returns the index of m in the array. If m is not in the array, foo returns the length of the array. E. At the end of the execution of foo, the array object referred to by a is automatically cleared from the memory by the garbage collector.

CSC142 Midterm 2 2 2. Consider the following class definition: public class C public static void foo() System.out.println("I am foo in C"); In some other class, to call the method foo in the C class, you would write: A. foo(); B. C.foo(); C. new C.foo(); D. A or B E. B or C 3. In a class definition, you read the following: public class C public void foo(int n)/*code*/ public boolean foo(char c)/*code*/ /* more code follows */ What can you say about the implementations of the foo method? A. It is an example of method overloading. B. foo is a static method within the C class C. It is illegal to use the name foo twice within the class. D. The return type should be boolean for both implementations of foo. E. One of the implementations of foo should be private.

CSC142 Midterm 2 3 4. Consider the following code fragment Rectangle[][] r = new Rectangle[2][]; r[0] = new Rectangle[3]; r[1] = new Rectangle[4]; What is r.length? A. 0 B. 2 C. 3 D. 4 E. 14 5. Which is an example of overloading the method that follows? int parsenumber(string numberstring) A. int parsethisnumber(string numberstring) B. int parsenumber(string num) C. int parsenumber(string num, String entry) 6. A constructor A. must have the same name as the class it is declared within. B. is used to create objects. C. may be overloaded. D. B and C E. A, B and C

CSC142 Midterm 2 4 7. Consider int[][] a = 1,2,3,4,5; int[] b = a[1]; b[0] = 10; What are the indices i and j of the array element a[i][j] that is equal to 10 after the above code fragment is executed? A. i=0 j=0 B. i=0 j=1 C. i=1 j=0 D. i=1 j=1 E. None of the elements of the array a is equal to 10 8. Consider the following table of integers 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 Among the following, which array would store the table with the minimum amount of memory used? A. int[][] a = new int[5][6]; B. int[][] a = new int[5][]; for(int i=0; i<a.length; i++) a[i] = new int[i]; C. int[][] a = new int[5][]; for(int i=0; i<a.length; i++) a[i] = new int[i+1]; D. int[][] a = new int[5][]; for(int i=0; i<a.length; i++) a[i] = new int[i+2]; E. int[][] a = new int[5][]; for(int i=0; i<a.length; i++) a[i] = new int[i+3];

CSC142 Midterm 2 5 9. Consider the following 2 methods defined in the same class public void foo(int i, double x)/*version1*/ public void foo(double x, int i)/*version 2*/ In another method in the same class, the following statement is written foo(1,2); Which version of foo is called? A. version 1 B. version 2 C. Can't tell. The compiler chooses randomly between version 1 and version 2 D. version 1 is called and then version 2. E. The code doesn't compile since the call is ambiguous 10. Consider the following method (Hint: try what(1,1,1)) public int what(int a, int b, int c) if (a<b && a<c) return a; if (b<a && b<c) return b; if (c<a && c<b) return c; What comment can be offered about this method? A. what returns the smallest of the three integers a, b and c B. what always returns the value of a C. what always returns the value of b D. what always returns the value of c E. The method is incorrect, because it does not always return a value.

CSC142 Midterm 2 6 11. Consider the following code fragment public int mystery(int a, int b) if (b==1) return a; else return a + mystery(a,b-1); What is the value of mystery(2,3)? A. 2 B. 4 C. 6 D. 8 E. the program generates a run time error (infinite recursion) 12. Still referring to the code fragment of the previous question, what is the value of mystery(2,0)? A. 2 B. 4 C. 0 D. 1 E. the program generates a run time error (infinite recursion)

CSC142 Midterm 2 7 13. Consider the code fragment: int x=2; int[] a = new int[2]; String s = "Red"; s = foo(x,a,s); System.out.println("x="+x+" a[0]="+a[0]+" s="+s); // method foo public String foo(int i, int[] j, String k) i= i+1; j[0] = j[0]+1; k = "Blue"; return k; What is printed? A. x=2 a[0]=0 s=red B. x=3 a[0]=0 s=red C. x=2 a[0]=1 s=red D. x=3 a[0]=0 s=blue E. x=2 a[0]=1 s=blue. 14. If the instance variables of the Employee class are declared as follows, which of the following statements is most likely to be in the constructor of this class? private String name; private Address address; private long employeenumber; A. address = 0; B. address = " "; C. address = new Address(); D. employeenumber = "11233444"; E. employeenumber = 143.144;

CSC142 Midterm 2 8 15. In which of the following situations would it make most sense to code a static method rather than a regular method in a class that defines a bank account? A. a method that calculates the number of deposits made in an account B. a method that sets the bank account total C. a method that changes the annual interest rate for all bank accounts D. a method that returns the bank account balance E. a method that prints the bank account balance 16. What is the highest index value associated with the array that follows? int[] values = new int[x]; A. 0 B. x C. x + 1 D. x 1 E. can t tell from information given

CSC142 Midterm 2 9 17. A method, called something, has the following body switch(n) case 1: return 0; default: return 1 + something(n/3); What would be a correct signature for this method body?(correct means that it does not trigger any error or warning message at the compilation). A. public int something(int[] n) B. public double something(int[] n) C. public int something(int n[]) D. public int something(int n) E. public void something(int n) 18. Given the signature that you selected above, what is the value of something(3*3*3)? A. 0 B. 1 C. 2 D. 3 E. 4

CSC142 Midterm 2 10 19. Which of the following is NOT true regarding recursion and iteration? A. Any recursive method can be rewritten in an iterative form (with a loop) B. Recursive calls take time and consume additional memory C. In general, recursive algorithms lead to better performance than iterative algorithms D. A recursive method is a method that calls itself E. To terminate, a recursive algorithm must have a base case 20. Which of the following is an invalid two-dimensional array definition? A. double[][] values = new double[2][8]; B. double[][] values = new double[8][2]; C. double[][] values = new double[8][]; D. double[][] values = new double[][8]; E. double[][] values = new double[2][0];