Do not start the test until instructed to do so!

Similar documents
Fall 2002 Page 1 of 9 READ THIS NOW!

Spring 2002 Page 1 of 8 READ THIS NOW!

CS 1044 Programming in C++ Test 1 Spring 2011 Form B Page 1 of 12 READ THIS NOW!

READ THIS NOW! Do not start the test until instructed to do so!

Do not start the test until instructed to do so!

CS 1044 Programming in C++ Test 1 READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties.

READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Do not start the test until instructed to do so!

CS 1704 Intro Data Structures and Software Engineering Test 2 Fall 2001 READ THIS NOW!

Chapter 6 Introduction to Defining Classes

CS111: PROGRAMMING LANGUAGE II

Final Exam. COMP Summer I June 26, points

Introduction to Programming Using Java (98-388)

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Chapter 4: Writing Classes

CS 101 Exam 1 Spring 200 Id Name

Anatomy of a Class Encapsulation Anatomy of a Method

CS 111X - Fall Test 1

Sri Vidya College of Engineering & Technology

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

NATIONAL UNIVERSITY OF SINGAPORE

Objects and Classes Lecture 2

CS 101 Spring 2006 Final Exam Name: ID:

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

CS1083 Week 2: Arrays, ArrayList

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming

PROGRAMMING FUNDAMENTALS

APCS Semester #1 Final Exam Practice Problems

NATIONAL UNIVERSITY OF SINGAPORE

CSE 131S Introduction to Computer Science Summer SON Exam I

CS260 Intro to Java & Android 03.Java Language Basics

Lab5. Wooseok Kim

JAVA GUI PROGRAMMING REVISION TOUR III

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

Computer Science II (20073) Week 1: Review and Inheritance

11/19/2014. Objects. Chapter 4: Writing Classes. Classes. Writing Classes. Java Software Solutions for AP* Computer Science A 2nd Edition

Prelim 1. CS 2110, 13 March 2018, 5:30 PM Total Question Name Short answer

Objects and Classes -- Introduction

VARIABLES AND TYPES CITS1001

CSCE 206: Structured Programming in C++

Exam Percentage: / 55 = %

Ticket Machine Project(s)

Problem Score Max Score 1 Syntax directed translation & type

This exam is open book. Each question is worth 3 points.

CS 2505 Computer Organization I

EECS168 Exam 3 Review

Prelim 1. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

Project 6 Due 11:59:59pm Thu, Dec 10, 2015

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

Computer Science II (20082) Week 1: Review and Inheritance

Chief Reader Report on Student Responses:

CS558 Programming Languages

CS 101 Fall 2006 Midterm 3 Name: ID:

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 );

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Formatting Output & Enumerated Types & Wrapper Classes

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

CS 335 Lecture 02 Java Programming

Lecture 02, Fall 2018 Friday September 7

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

CS 101 Spring 2007 Midterm 2 Name: ID:

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

Table of Contents Date(s) Title/Topic Page #s. Chapter 4: Writing Classes 4.1 Objects Revisited

CS 170 Exam 1. Version: B Fall Name (as on OPUS):

JAVA Programming Language Homework I - OO concept

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Use the scantron sheet to enter the answer to questions (pages 1-6)

ECE 122. Engineering Problem Solving with Java

CS 314 Exam 2 Spring 2016

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

Lab5. Wooseok Kim

Padasalai.Net s Model Question Paper

Final Exam COMP Fall 2004 Dec 16, 2004

Computer Programming, I. Laboratory Manual. Final Exam Solution

COE 212 Engineering Programming. Welcome to Exam I Tuesday November 11, 2014

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

Give one example where you might wish to use a three dimensional array

Java Identifiers, Data Types & Variables

Language Features. 1. The primitive types int, double, and boolean are part of the AP

Here is a C function that will print a selected block of bytes from such a memory block, using an array-based view of the necessary logic:

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012

Methods. Methods. Mysteries Revealed

Objectives. Introduce static keyword examine syntax describe common uses

Inheritance and Interfaces

OBJECTS AND CLASSES CHAPTER. Final Draft 10/30/2011. Slides by Donald W. Smith TechNeTrain.com

public class TicketMachine Inner part omitted. public class ClassName Fields Constructors Methods

Lecture 13 & 14. Single Dimensional Arrays. Dr. Martin O Connor CA166

Anatomy of a Method. HW3 is due Today. September 15, Midterm 1. Quick review of last lecture. Encapsulation. Encapsulation

CS 3114 Data Structures and Algorithms Test 1 READ THIS NOW!

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Transcription:

CS 1054: Programming in Java Page 1 of 6 Form A READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties Failure to adhere to these directions will not constitute an excuse or defense Print your name in the space provided below Print your name and ID number on the Opscan form; be sure to code your ID number on the Opscan form. Code Form A on the opscan. Choose the single best answer for each question. If you mark more than one answer, it will be counted wrong. Unless a question determining whether given Java code is syntactically correct, assume that it is. The given code has been compiled and tested, except where there are deliberate errors. Unless a question specifically deals with Java import directives, you should assume the necessary library files have been imported. Note that questions about printed values disregard formatting completely. In questions/answers that require a distinction between integer and real vales, integers will be represented without a decimal point, whereas real values will have a decimal point, [1054 (integer), 1054.0 (real)]. When you have completed the test, sign the pledge at the bottom of this page and turn in the test and your Opscan. This is a closed-book, closed-notes examination. No calculators or other electronic devices may be used during this examination. You may not discuss (in any form: written, verbal or electronic) the content of this examination with any student who has not taken it. You must return this test form when you complete the examination. Failure to adhere to any of these restrictions is an Honor Code violation. There are 25 multiple-choice questions. Mark your answers on the test form, future reference, and on the Opscan. The answers you mark on the Opscan will be considered your future answers. Do not start the test until instructed to do so! Name: (print: Last name, First) VT PID: (print: campus email address) Pledge: On my honor, I have neither given nor received unauthorized aid on this examination. signature

CS 1054: Programming in Java Page 2 of 6 Form A 1. What is the root of the class hierarchy in Java? A. Object B. Class C. java.util D. ArrayList 2. In the Java language, how many classes can be instantiated from an object? A. 10 B. 9 C. 8 D. 7 E. 6 F. 4 G. 3 H. 2 E. Random F. String G. int 3. In the Java programming language, what does any file with extension.java contain? A. Source code D. Executable code B. Byte code E. Unicode C. Java virtual machine 4. In the Java programming language, what does any file with extension.class contain? A. Source code D. Graphics code B. Byte code E. Plain text C. Java virtual machine 5. What is printed out when the following code is executed? int a, b, c; a = 2; a = a + 4; b = 2; c = a - b; System.out.println(2+c+c); I. 1 J. 0 A. 2cc B. 10 C. 244 D. 2+4+4 E. 8 The next seven questions are based on the following code. Assume that this method is in a class called Calculator and value is a instance variable of type int declared earlier in the code. public void calcvalue(int x, int y) { int val; val = x*x + y*y; value = val; 6. What type of method is calcvalue? A. Mutator B. Accessor C. Mutator and Accessor D. Instance method E. Class method F. A and E above G. A and D above 7. How many formal parameters are present in the method signature? A. 0 C. 2 B. 1 D. 3 E. 4 F. 5

CS 1054: Programming in Java Page 3 of 6 Form A 8. Which is the correct way of invoking this method from within the same class? A. Calculator.calcValue(10, 20); E. this.calcvalue(10,10); B. Calculator.calcValue(); F. A and D above C. calcvalue(10,10); G. C and E above D..calcValue(); 9. Assume that a new object has been created of type Calculator as follows: Calculator calc = new Calculator(); Which is the correct way of invoking the calcvalue method in object calc? A. Calculator.calcValue(10, 20); E. this.calcvalue(10,10); B. calc.calcvalue(); F. A and D above C. calcvalue(10,10); G. C and E above D..calcValue(); 10. What is the return type in the calcvalue method? A. int B. float C. String D. bool E. void F. public G. private 11. What is the lifetime of the variable val in the code above? A. The class definition of Calculator B. The body of method calcvalue C. The class definition of calcvalue D. None of the above 12. What is the lifetime of the variable value in the code above? A. The class definition of Calculator B. The body of method calcvalue C. The class definition of calcvalue D. None of the above 13. Which one of the following statements describing objects and classes is true? A. Classes are instances of objects. B. Objects and classes are instances of structures. C. Reference variables refer to classes. D. Objects are instances of classes. E. All of the above are true. The next two questions are based on the following code. int index; int sum = 0; for (index = 0; index < 5; index++) { sum += index; System.out.println( The value of sum = + sum);

CS 1054: Programming in Java Page 4 of 6 Form A 14. What is printed out at the end of the for loop? A. The value of sum = 3 B. The value of sum = 6 C. The value of sum = 10 D. The value of sum = 20 E. None of the above 15. What is the value of variable index at the end of the for loop? A. 0 E. 4 B. 1 F. 5 C. 2 G. 6 D. 3 16. Which keyword in Java identifies a variable to be a class variable? A. void F. static B. public G. class C. private H. interface D. int I. None of the above E. import The next two questions are based on the following piece of code int[] num = {10, 20, 30, 40, 50; ArrayList al = new ArrayList(); for (int index = 1; index <= 5; index++) { al.add(new Integer(num[index-1]*num[index-1])); Iterator it = al.iterator(); System.out.print("Numbers = "); while (it.hasnext()) { System.out.print(" " + it.next()); System.out.println(); 17. What is printed out when the code above is executed? A. Numbers = 1 2 3 4 5 B. Numbers = 100 400 900 1600 2500 C. Numbers = 0 1 2 3 4 5 D. Numbers = 100 400 900 1600 E. Numbers = 10 20 30 40 50 F. The code will not compile G. The code will give a runtime error. 18. What will be printed out if you change the line inside the for loop to the following and execute the code? al.add(new Integer(num[index]*num[index])); A. Numbers = 100 400 900 1600 2500 B. Numbers = 1 2 3 4 5

CS 1054: Programming in Java Page 5 of 6 Form A C. Numbers = 0 1 2 3 4 5 D. Numbers = 100 400 900 1600 E. Numbers = 10 20 30 40 50 F. The code will not compile G. The code will give a runtime error. 19. How many constructor methods can a class definition have, provided each constructor method has different parameters? A. 0 E. 4 B. 1 F. All of the above C. 2 G. None of the above D. 3 20. What keyword in Java is used for utilizing classes from some external package? A. include B. library C. package D. extends E. interface F. import G. None of the above The next three questions are based on the following code. public class mysquare { private int size = 0; // size of the square // Square is positioned at (xposition, yposition) private int xposition = 0; private int yposition = 0; public mysquare() { size = 30; // default size xposition = 10; // default x coordinate of position yposition = 10; // default y coordinate of position public mysquare(int s, int x, int y) { size = s; xposition = x; yposition = y; public void changesize(int s) { size = s; public void changexposition(int x) { xposition = x; public void changeyposition(int y) { yposition = y; 21. What does the following statement accomplish? mysquare square = new mysquare(); A. Define an instance named mysquare of type square B. Define an instance named square of type mysquare with size 30 and positioned at (10,10) C. Define an instance named square of type mysquare with size 30 and positioned at (0,0) D. Define an instance of type square of type Square with size 30 and positioned at (10,10) E. All of the above

CS 1054: Programming in Java Page 6 of 6 Form A 22. What do the following statements accomplish? mysquare square = new mysquare(20,30,30); A. Define an instance named mysquare of type square B. Define an instance named square of type mysquare with size 30 and positioned at (10,10) C. Define an instance of type square of type Square with size 20 and positioned at (30,30) D. Define an instance named square of type mysquare with size 20 and positioned at (30,30) E. All of the above 23. What are the values of size, xposition and yposition when the following code is executed? mysquare square = new mysquare(); square.changesize(40); square.changexposition(30); A. 30, 10 and 10 B. 10, 20 and 20 C. 20, 20 and 20 D. 30, 30 and 30 E. 40, 30 and 10 G. There is a syntax error in the above code. 24. Which of the following statements is false? A. Field variables should be made public B. Local variables exist only within the scope of a method C. Private variables are accessible only within the same class D. Only methods that are intended for other classes should be made public E. All the above statements are false. F. All the above statements are true. 25. Which of the following statements is false? A. Class variables reside in each object instance B. Class variables reside only in the class itself C. Class variables are defined using the keyword static D. Class variables are used if the variable has the same value in each object E. All the above statements are false. F. All the above statements are true.