CS2401 QUIZ 5 February 26, questions / 20 points / 20 minutes NAME:..

Similar documents
Practice Questions for Chapter 9

Chapter 8 Objects and Classes Dr. Essam Halim Date: Page 1

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

CS 113 PRACTICE FINAL

CIS 265/506 Exam1 Spring 2012 Prof. V. Matos Exam Last Name First Name:

Questions Answer Key Questions Answer Key Questions Answer Key

Questions Answer Key Questions Answer Key Questions Answer Key

Computer Programming, I. Laboratory Manual. Final Exam Solution

Questions Answer Key Questions Answer Key Questions Answer Key

Chapter 6 Arrays. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Chapter 1: Introduction to Computers, Programs, and Java

CS1150 Principles of Computer Science Arrays

CS 113 MIDTERM EXAM 2 SPRING 2013

Chapter 6 Single-dimensional Arrays

Module 7: Arrays (Single Dimensional)

Tutorial 11. Exercise 1: CSC111 Computer Programming I. A. Write a code snippet to define the following arrays:

Programming - 2. Common Errors

CS115. Chapter 17 Exception Handling. Prof. Joe X. Zhou Department of Computer Science. To know what is exception and what is exception handling

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Java-Array. This tutorial introduces how to declare array variables, create arrays, and process arrays using indexed variables.

14. Array Basics. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

CIS 265 Summer 2015 Exam 1 First Name Last Name

CIS265 - Spring Exam 2 First Name Last Name CSU#

Programs as Models. Procedural Paradigm. Class Methods. CS256 Computer Science I Kevin Sahr, PhD. Lecture 11: Objects

Chapter 6 Single-Dimensional Arrays. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.

CS1150 Principles of Computer Science Arrays

Introduction to Programming Using Java (98-388)

Practice Midterm 1. Problem Points Score TOTAL 50

Object Oriented Programming in C#

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved

CS201 Latest Solved MCQs

Opening Problem EXAMPLE. 1. Read one hundred numbers, 2. compute their average, and 3. find out how many numbers are above the average.

Reminder the scope of a variable is the part of the program where that variable is visible Will this compile?

CS 162, Lecture 25: Exam II Review. 30 May 2018

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Arrays. Introduction to OOP with Java. Lecture 06: Introduction to OOP with Java - AKF Sep AbuKhleiF - 1

Arrays. Eng. Mohammed Abdualal

Java Loop Control. Programming languages provide various control structures that allow for more complicated execution paths.

Variables, Types, Operations on Numbers

Topic 10. Abstract Classes. I prefer Agassiz in the abstract, rather than in the concrete.

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

CS170 Introduction to Computer Science Midterm 2

COE318 Lecture Notes Week 10 (Nov 7, 2011)

Programming by Delegation

Protection Levels and Constructors The 'const' Keyword

Question 2. [5 points] Given the following symbolic constant definition

1 Inheritance (8 minutes, 9 points)

int a; int b = 3; for (a = 0; a < 8 b < 20; a++) {a = a + b; b = b + a;}

CS159. Nathan Sprague

AP CS Unit 7: Arrays Exercises

int[] a; a = new int[8]; a[0] = 1; a[1] = 1; for (int i = 2; i < 8; i++) a[i] = a[i-1] - a[i-2];

Chapter 7 Single-Dimensional Arrays

Objectives. Introduce static keyword examine syntax describe common uses

Lecture 10 Declarations and Scope

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

WES-CS GROUP MEETING #9

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

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

Chapter 12: How to Create and Use Classes

Array. Lecture 12. Based on Slides of Dr. Norazah Yusof

Linked Lists. College of Computing & Information Technology King Abdulaziz University. CPCS-204 Data Structures I

THE NAME OF THE CONSTRUCTOR AND DESTRUCTOR(HAVING (~) BEFORE ITS NAME) FUNCTION MUST BE SAME AS THE NAME OF THE CLASS IN WHICH THEY ARE DECLARED.

Announcements. PS 4 is ready, due next Thursday, 9:00pm. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

COS 126 General Computer Science Spring Written Exam 1

Quiz 1 Unit 5A Arrays/Static Name

Exception-Handling Overview

Chapter 7: Single-Dimensional Arrays. Declaring Array Variables. Creating Arrays. Declaring and Creating in One Step.

Introduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples

COMP 103. Mid Trimester Test 17 August 2006

Java Object Oriented Design. CSC207 Fall 2014

Common Misunderstandings from Exam 1 Material

Arrays. Chapter The Java Array Object. Goals

Linked List Practice Questions

Come and join us at WebLyceum

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

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Largest Online Community of VU Students

VARIABLES AND TYPES CITS1001

Question 1a) Trace of program

CA31-1K DIS. Pointers. TA: You Lu

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

CMPS 134: Computer Science I Fall 2011 Test #1 October 5 Name Dr. McCloskey

CS115 Principles of Computer Science

Points To Remember for SCJP

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

CS 161 Exam II Winter 2018 FORM 1

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

CS 455 Final Exam Spring 2018 [Bono] May 8, 2018

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

Name: Code: Lab: (circle one) 12MW 2MW 4MW 5:30MW 7:00MW

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

CSIS-120 Final Exam Fall 2015 Name:

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Fundamental Concepts and Definitions

CSE 142 Su01 Midterm 1 Sample Solution page 1 of 5

Transcription:

CS2401 QUIZ 5 February 26, 2014 18 questions / 20 points / 20 minutes NAME:.. Questions on Objects and Classes 1 An object is an instance of a. A. program B. class C. method D. data 2 is invoked to create an object. A. A constructor B. The main method C. A method with a return type D. A method with the void return type 3 What is wrong in the following code? class TempClass { int i; public void TempClass(int j) { int i = j; public class C { TempClass temp = new TempClass(2); A. The program has a compilation error because TempClass does not have a default constructor. B. The program has a compilation error because TempClass does not have a constructor with an int argument. C. The program compiles fine, but it does not run because class C is not public. D. The program compiles and runs fine. 3a If anything was wrong with the code of Question 3, show how to fix it:

4 Given the declaration Circle x = new Circle(), which of the following statement is most accurate. A. x contains an int value. B. x contains an object of the Circle type. C. x contains a reference to a Circle object. D. You can assign an int value to x. 5 Analyze the following code. int x; public Test(String t) { System.out.println("Test"); Test test = null; System.out.println(test.x); A. The program has a compile error because test is not initialized. B. The program has a compile error because x has not been initialized. C. The program has a compile error because you cannot create an object from the class that defines the object. D. The program has a compile error because Test does not have a default constructor. E. The program has a runtime NullPointerException because test is null while executing test.x. 6 The default value for data field of a boolean type, numeric type, object type is, respectively. A. true, 1, Null B. false, 0, null C. true, 0, null D. true, 1, null E. false, 1, null 7 Analyze the following code: double radius; final double PI= 3.15169; double area = radius * radius * PI; System.out.println("Area is " + area); A. The program has compile errors because the variable radius is not initialized. B. The program has a compile error because a constant PI is defined

inside a method. C. The program has no compile errors but will get a runtime error because radius is not initialized. D. The program compiles and runs fine. Questions on Arrays 8 What is the output of the following code? double[] mylist = {1, 5, 5, 5, 5, 1; double max = mylist[0]; int indexofmax = 0; for (int i = 1; i < mylist.length; i++) { if (mylist[i] > max) { max = mylist[i]; indexofmax = i; System.out.println(indexOfMax); A. 0 B. 1 C. 2 D. 3 E. 4 9 Analyze the following code: int[] x = new int[5]; int i; for (i = 0; i < x.length; i++) x[i] = i; System.out.println(x[i]); A. The program displays 0 1 2 3 4. B. The program displays 4. C. The program has a runtime error because the last statement in the main method causes ArrayIndexOutOfBoundsException. D. The program has a compile error because i is not defined in the last statement in the main method. 10 (for-each loop) Analyze the following code: double[] x = {2.5, 3, 4; for (double value: x) System.out.print(value + " ");

A. The program displays 2.5, 3, 4 B. The program displays 2.5 3 4 C. The program displays 2.5 3.0 4.0 D. The program displays 2.5, 3.0 4.0 E. The program has a syntax error because value is undefined. 11 What is output of the following code: int[] x = {120, 200, 016; for (int i = 0; i < x.length; i++) System.out.print(x[i] + " "); A. 120 200 16 B. 120 200 14 C. 120 200 20 D. 016 is a compile error. It should be written as 16. 12 What will be displayed by the following code? class Test { int[] list1 = {1, 2, 3; int[] list2 = {1, 2, 3; list2 = list1; list1[0] = 0; list1[1] = 1; list2[2] = 2; for (int i = 0; i < list1.length; i++) System.out.print(list1[i] + " "); A. 1 2 3 B. 1 1 1 C. 0 1 2 D. 0 1 3 13 Analyze the following code: public class Test1 { xmethod(new double[]{3, 3); xmethod(new double[5]); xmethod(new double[3]{1, 2, 3); public static void xmethod(double[] a) { System.out.println(a.length); A. The program has a compile error because xmethod(new double[]{3, 3)

is incorrect. B. The program has a compile error because xmethod(new double[5]) is incorrect. C. The program has a compile error because xmethod(new double[3]{1, 2, 3) is incorrect. D. The program has a runtime error because a is null. 14 Suppose a method p has the following heading: public static int[] p() What return statement may be used in p()? A. return 1; B. return {1, 2, 3; C. return int[]{1, 2, 3; D. return new int[]{1, 2, 3; Questions on Linked Lists 15 What is/are the main advantage(s) of using linked lists as opposed to arrays? A. easy to access B. flexible C. their elements do not all have to be of the same type D. both 16 What do simple linked-list nodes consist of? A. specific content B. address C. a Boolean value that indicates when the current node is the last one 17 In a linked list, elements can be added: A. at the start of the list B. at the end of the list C. anywhere 18 Assuming that head is the first node of a linked list L, traversing L is as simple as repeatedly executing: first = first.link. A. Yes B. No Justify your answer: