Midterm Exam CS 251, Intermediate Programming March 6, 2015

Similar documents
Midterm Exam CS 251, Intermediate Programming March 12, 2014

Midterm Exam CS 251, Intermediate Programming October 8, 2014

Final Exam CS 251, Intermediate Programming December 10, 2014

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014

Final Exam CS 152, Computer Programming Fundamentals December 5, 2014

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

Final Exam CS 251, Intermediate Programming December 13, 2017

CS 251, Intermediate Programming Midterm Exam October 9, 2013

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)

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

CS159. Nathan Sprague

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

Declarations and Access Control SCJP tips

CS 251 Intermediate Programming Inheritance

CS260 Intro to Java & Android 03.Java Language Basics

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

Programming II (CS300)

Questions Answer Key Questions Answer Key Questions Answer Key

CMPSCI 187 Midterm 1 (Feb 17, 2016)

1 Shyam sir JAVA Notes

CO Java SE 8: Fundamentals

CS159. Nathan Sprague

CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2013

Programming II (CS300)

Final Exam. COMP Summer I June 26, points

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

1 Method Signatures and Overloading (3 minutes, 2 points)

Introduction to Programming Using Java (98-388)

Lab5. Wooseok Kim

CS211 Spring 2005 Prelim 1 March 10, Solutions. Instructions

CMSC 132: Object-Oriented Programming II

Instruction to students:

Prelim 1. Solution. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer

Lab5. Wooseok Kim

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Computer Sciences 302 Final Exam Information & Sample Questions

More On inheritance. What you can do in subclass regarding methods:

Programming overview

Introduction to Java

CMSC132 Summer 2018 Midterm 1

Key Java Simple Data Types

Prelim 1. Solution. CS 2110, 14 March 2017, 5:30 PM Total Question Name Short answer

Examination Questions Midterm 1

CMSC 331 Second Midterm Exam

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Computational Expression

Java Simple Data Types

CMSC 202 Final May 19, Name: UserID: (Circle your section) Section: 101 Tuesday 11: Thursday 11:30

CSE 1223: Exam II Autumn 2016

Vendor: Oracle. Exam Code: 1Z Exam Name: Java SE 7 Programmer I. Version: Demo

Crash Course Review Only. Please use online Jasmit Singh 2

CLASS DESIGN. Objectives MODULE 4

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

CS 61B Discussion 5: Inheritance II Fall 2014

CS 139 Practice Midterm Questions #2

Vendor: Oracle. Exam Code: 1Z Exam Name: Java SE 8 Programmer. Version: Demo

F I N A L E X A M I N A T I O N

CSC 1351 The Twelve Hour Exam From Hell

CS 101 Fall 2006 Midterm 1 Name: ID:

Problem Score Max Score 1 Syntax directed translation & type

Sample Examination Paper Programming and Software Development

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

Questions Answer Key Questions Answer Key Questions Answer Key

CS 11 java track: lecture 3

Big software. code reuse: The practice of writing program code once and using it in many contexts.

COMP 401 Spring 2013 Midterm 2

CMSC132 Summer 2018 Midterm 1. Solution

CSE331 Winter 2014, Final Examination March 17, 2014 Please do not turn the page until 8:30. Rules:

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

COMPUTER SCIENCE DEPARTMENT PICNIC. Operations. Push the power button and hold. Once the light begins blinking, enter the room code

Fundamentals of Object Oriented Programming

JAVA OBJECT-ORIENTED PROGRAMMING

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2014

COMP 401 Spring 2013 Midterm 2

Questions Answer Key Questions Answer Key Questions Answer Key

Polymorphism. return a.doublevalue() + b.doublevalue();

Chapter 4 Defining Classes I

CS365 Midterm -- Spring 2019

Programming with Java

CS 251 Intermediate Programming Java Basics

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

CS 113 MIDTERM EXAM 2 SPRING 2013

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

CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016

JAVA Programming Language Homework I - OO concept

INSTRUCTIONS TO CANDIDATES

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

Index COPYRIGHTED MATERIAL

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

Full file at Chapter 2 - Inheritance and Exception Handling

CS-202 Introduction to Object Oriented Programming

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong:

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

15CS45 : OBJECT ORIENTED CONCEPTS

CPSC 233 Final Exam, Winter 2003 DEPARTMENT OF COMPUTER SCIENCE THE UNIVERSITY OF CALGARY Time: 120 minutes 100 marks total L02, L03, L04

Transcription:

Midterm Exam CS 251, Intermediate Programming March 6, 2015 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible answers. This is a closed book exam. However, each student is allowed to bring one page of notes to the exam. Print your name at the top of every page. Question: 1 2 3 4 5 6 7 8 Total Points: 12 21 12 8 15 12 10 10 100 Score: 1. Multiple Choice Questions (a) Which code would you use to instantiate a new TreeSet that could only hold Strings? A.... = <String>TreeSet(); B.... = new TreeSet<String>; C.... = TreeSet<String>(); D.... = new TreeSet<String>(); E.... = String<TreeSet>(); F.... = new String[TreeSet]; (b) Which combination of modifiers could not be used together to modify a class? A. public static abstract B. protected abstract final C. private static final (c) Which combination of modifiers could be used together to modify a member variable? A. public static abstract B. protected abstract final C. private static final (d) What is the value of the following expression? 2 + 4 + "six"+ 8 A. "6six8" B. "24six8" C. "six14" D. 20 E. This expression would result in a compilation error. (e) A member declared with a protected access modifier is not always visible to: A. the class in which it is declared. B. classes in the same package as the class in which it is declared. C. classes that extend the class in which it is declared. D. parent classes of the class in which it is declared. E. classes nested inside the class in which it is declared. (f) Which of the following is true of an unchecked exception? A. It must be handled at compile time with a try/catch construct. B. It is thrown because of unavoidable circumstances, such as a file not being found. C. It extends RuntimeException. D. It cannot be caught at runtime. Page 1 of 8

2. Why do the following code snippets not compile? (Explain in one sentence each.) (a) (3) int single = 1; int double = 2; (b) (3) List < String > names = new List < String >(); (c) (3) Set < double > values ; (d) (3) Map < Integer, String > idtonamemap = HashMap < >(); (e) (3) double pi = 3. 14159 (f) (3) if (x = 5) System. out. println (x); (g) (3) public static String mymethod ( int x) { final String result = " Big "; if(x < 10) { result = " Small "; return result ; Page 2 of 8

3. Short answer (a) What is the keyword instanceof used for? (3) (b) When reading the API, how can you recognize a generic class? (3) (c) Name one method in the Collections class, and explain what it does. (3) (d) It is possible to declare a main method in every single class of a project. What would be (3) the point of doing this? 4. Consider the following classes. public class Parent { public void method1 ( int i) { public static void method2 ( int i) { public void method3 ( int i) { public static void method4 ( int i) { public class Child extends Parent { public void method1 ( float i) { public static void method2 ( float i) { public void method3 ( int i) { public static void method4 ( int i) { (a) Does method1 in Child override, overload, or hide the method in Parent? (b) Does method2 in Child override, overload, or hide the method in Parent? (c) Does method3 in Child override, overload, or hide the method in Parent? (d) Does method4 in Child override, overload, or hide the method in Parent? (a) (b) (c) (d) Page 3 of 8

5. Consider the following interface. public interface TestInterface { void dostuff ( String s); boolean isittrue ( int i, double x); For each of the following: Does this class implement the interface? If it does not, what is wrong with the implementation? (a) (3) public interface TestImplementation implements TestInterface { public void dostuff ( String s) { public boolean isittrue ( int i, double x) { return true ; (b) (3) public class TestImplementation implements TestInterface { public void dostuff ( String s) { public boolean isittrue ( int i, double x) { return true ; public void dostuff ( int i) { Page 4 of 8

(c) (3) public class TestImplementation extends TestInterface { public void dostuff ( String s) { public boolean isittrue ( int i, double x) { return true ; (d) (3) public class TestImplementation { public void dostuff ( String s) { public boolean isittrue ( int i, double x) { return false ; (e) (3) public class TestImplementation implements TestInterface { public boolean isittrue ( int a, double b) { return false ; public void dostuff ( String x) { Page 5 of 8

6. Consider the following classes. What is the output of this code? (12) public class Foo { protected String a; protected int b; public Foo () { this (" Goodbye "); public Foo ( String a) { this (42, a); public Foo ( int a, String b) { this.a = b; this.b = a; public void printstuff () { System. out. println (a); System. out. println (b); public class Bar extends Foo { protected double c; public Bar ( int a, String b) { this (2.5, b, a); public Bar ( double a, String b, int c) { this.c = a*c; System. out. println (a); System. out. println (b); System. out. println (c); public void printstuff () { super. printstuff (); System. out. println (c); public static void main ( String [] args ) { Foo x = new Bar (3, " Hello "); x. printstuff (); Page 6 of 8

7. Consider the following class. What is the output of this code? (10) public class Baz { private static int x = 2; private int y = 10; public void dostuff () { System. out. println (x); System. out. println (y); x += y; y - -; public static void main ( String [] args ) { Baz b1 = new Baz (); b1. dostuff (); b1. dostuff (); Baz b2 = new Baz (); b2. dostuff (); b1. dostuff (); b2. dostuff (); Page 7 of 8

8. Write a method that takes a Collection of String objects (any type of collection, not a specific (10) implementation) and returns the average number of characters in all the Strings. In other words, return the average of the lengths of the Strings in the Collection. If the collection is empty, return -1. Page 8 of 8