Final Exam CS 251, Intermediate Programming December 10, 2014

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

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

CS 251, Intermediate Programming Midterm Exam October 9, 2013

Midterm Exam CS 251, Intermediate Programming October 8, 2014

Midterm Exam CS 251, Intermediate Programming March 6, 2015

Final Exam CS 251, Intermediate Programming December 13, 2017

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

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

Name: CSC143 Exam 1 1 CSC 143. Exam 1. Write also your name in the appropriate box of the scantron

CSE 113 A. Announcements - Lab

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

Csci 102: Sample Exam

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

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

Declarations and Access Control SCJP tips

ITI Introduction to Computing II

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Final Exam. COMP Summer I June 26, points

Introduction to Programming Using Java (98-388)

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

ITI Introduction to Computing II

CS260 Intro to Java & Android 03.Java Language Basics

CS 251 Intermediate Programming Inheritance

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

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer

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

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Csci 102: Sample Exam

CS 251 Intermediate Programming More on classes

Chapter 4 Defining Classes I

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

Overriding Variables: Shadowing

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

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

CS159. Nathan Sprague

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

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

I. True/False: (2 points each)

CS 11 java track: lecture 3

CS Exam 1 Review Suggestions

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

CSE 131 Introduction to Computer Science Fall Final Exam

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

CMSC 132: Object-Oriented Programming II

CS211 Spring 2005 Prelim 1 March 10, Solutions. Instructions

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

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

Java classes cannot extend multiple superclasses (unlike Python) but classes can implement multiple interfaces.

Inheritance. Chapter 7. Chapter 7 1

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

RAIK 183H Examination 2 Solution. November 11, 2013

Introduction to Programming (CS112): Sample

CS111: PROGRAMMING LANGUAGE II

Questions Answer Key Questions Answer Key Questions Answer Key

RAIK 183H Examination 2 Solution. November 10, 2014

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

Final Exam Practice. Partial credit will be awarded.

CS 134 Midterm Fall 2006

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

Sample Examination Paper Programming and Software Development

Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

First Name: AITI 2004: Exam 2 July 19, 2004

13 th Windsor Regional Secondary School Computer Programming Competition

C++ Inheritance and Encapsulation

CS 520 Theory and Practice of Software Engineering Fall 2017

CMSC 331 Second Midterm Exam

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

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

Inheritance and Interfaces

Programming Languages and Techniques (CIS120)

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

CS170 Introduction to Computer Science Midterm 2

1 Inheritance (8 minutes, 9 points)

CSC 1351 The Twelve Hour Exam From Hell

CS 180 Final Exam Review 12/(11, 12)/08

Inheritance: Definition

About This Lecture. Data Abstraction - Interfaces and Implementations. Outline. Object Concepts. Object Class, Protocol and State.

Sets and Maps. Sets Maps The Comparator Interface Sets and Maps in Java Collections API. Review for Exam Reading:

8. Polymorphism and Inheritance

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

Chapter 6 Introduction to Defining Classes

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

APCS Semester #1 Final Exam Practice Problems

Inheritance and Polymorphism. CS180 Fall 2007

Question: Total Points: Score:

CS 1331 Fall 2016 Exam 2

Coverage of Part 2. A Brief Introduction to Java for C++ Programmers: Part 2. import: using packages

Programming with Java

Midterm assessment - MAKEUP Fall 2010

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2012

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2014

CS 116 Week 8 Page 1

NATIONAL UNIVERSITY OF SINGAPORE

CSCI 201L Written Exam #1 Fall % of course grade

Preview from Notesale.co.uk Page 3 of 36

CS1004: Intro to CS in Java, Spring 2005

Classes. Classes as Code Libraries. Classes as Data Structures

CSE351 Winter 2016, Final Examination March 16, 2016

Object Orientation Fourth Story. Bok, Jong Soon

Transcription:

Final Exam CS 251, Intermediate Programming December 10, 2014 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 9 10 Total Points: 6 18 12 10 6 6 14 12 10 6 100 Score: 1. Which of the following are not Java keywords? Select all that apply. (6) A. bool B. break C. do D. enum E. import F. include G. int H. switch I. if J. then K. else L. elif 2. Why do the following snippets of code not compile? (Explain in one sentence each.) (a) Map<String,int> wordcounts; (3) (b) if (x = 5) System.out.println(x); (3) Page 1 of 10

(c) (3) public class MyClass { private int x = 10; public static void main ( String [] args ) { (d) boolean break = true; (3) (e) int x = 5 (3) (f) (3) public class Test { private static final int x = 5; public void method () { for ( int i = 0; i < x; i ++) { System. out. println (i); System. out. println (x + ", " + i); Page 2 of 10

3. (a) Describe the differences between a checked and an unchecked exception. (4) (b) Why can t you have a class declared as final abstract? (4) (c) If you have not written a default (parameter-less) constructor for your class, but you have (4) written a constructor that takes at least one parameter, can you still call the default constructor on that class? Why or why not? Page 3 of 10

4. Multiple choice questions. Select the single best answer. (a) Which code would you use to instantiate a new TreeSet that could only hold Strings? (2) A.... = <String>TreeSet(); B.... = new TreeSet<String>; C.... = TreeSet<String>(); D.... = new TreeSet(String); E.... = new TreeSet<String>(); F.... = String<TreeSet>(); G.... = new String[TreeSet]; (b) A member declared with a protected access modifier is not always visible to: (2) A. the class in which it is declared. B. parent classes of the class in which it is declared. C. classes that extend the class in which it is declared. D. classes nested inside the class in which it is declared. (c) A static variable with no access modifier could not be accessed by: A. A static method in the same class. B. A non-static method in the same class. C. A protected method defined within the same package. D. A final method defined in a different package. (2) (d) What is displayed when the following code is compiled and executed? (2) public class StringCompare { public static void main ( String [] args ) { String s1 = new String (" Test "); String s2 = new String (" Test "); if (s1!= s2) System. out. println (" Different "); if (s1. equals (s2 )) System. out. println (" Equals "); A. Different Equals B. Equals C. Different D. The code compiles, but nothing is displayed upon execution. E. The code fails to compile. (e) 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. (2) Page 4 of 10

5. Write code to create a JButton with text Click Here that prints Button was clicked! to (6) the console when it is pressed. Only create the button, you do not have to add it to a layout, show a window, etc. Use an anonymous class for the action listener. 6. Java uses layout managers to keep track of where components added to a GUI are being (6) displayed. Please pick a layout manager class and describe how components are laid out within it. Page 5 of 10

7. Remember this mess of code from a quiz earlier this term? (Don t worry, I don t need you to (14) tell me what the output will be this time. Just answer the question on the next page.) public class Parent { public int x = 0; public Parent ( int x) { this.x = x; public class InnerChild extends Parent { public int x = 1; public InnerChild ( int x) { super (2* x); this.x = x; public void innermethod ( int x) { outermethod (x); System. out. println ( this.x); System. out. println ( super.x); System. out. println ( Parent. this.x); Output: 2 37 3 14 4 10 4 5 10 37 public void outermethod ( int x) { System. out. println ( this.x); public static void main ( String [] args ) { int x = 37; Parent p = new Parent ( x); x = 6; Parent c1 = p. new InnerChild ( x + 1); InnerChild c2 = p. new InnerChild ( x - 1); p. outermethod (2); c1. outermethod (3); c2. innermethod (4); Page 6 of 10

Which of the following lines of code would cause an error when placed in the main method of Parent after the code that is currently there? Select all that apply. A. p.innermethod(5); B. ((InnerChild)p).innerMethod(5); C. c1.innermethod(5); D. ((InnerChild)c1).innerMethod(5); E. c2.outermethod(5); F. Parent p2 = p; G. Parent p2 = c2; H. Parent p2 = new Parent(10); I. Parent p2 = new Parent(10).new InnerChild(20); J. InnerChild c3 = p; K. InnerChild c3 = c2; L. InnerChild c3 = c2.new InnerChild(20); M. InnerChild c3 = new Parent(10); N. InnerChild c3 = new Parent(10).new InnerChild(20); Page 7 of 10

8. Consider the following classes. What is the output of this code? (12) public class Foo { protected int x; protected double y; protected String z; public Foo () { this (" Winter "); public Foo ( String x) { this (x, x. length ()); public Foo ( String x, int y) { this.x = y; this.y = y / 8.0; this.z = x; public void print ( String x) { System. out. println (y); System. out. println (z); public class Bar extends Foo { public Bar ( String x) { super (" Exam "); public void print ( int x) { print (x * 1.5); public void print ( String x) { print (x. length () / 2); System. out. println (y); public static void main ( String [] args ) { Foo test = new Bar (" Final "); test. print ("CS" + 251); public void print ( double y) { System. out. println (y); System. out. println (z); Page 8 of 10

9. Write a method that takes a Collection of String objects and the number of characters in all (10) the Strings. In other words, return the sum of the lengths of the Strings in the Collection. Page 9 of 10

10. Please organize the following objects in a feasible inheritance hierarchy: Airplane, Automobile, (6) Blimp, Boat, Car, FlyingMachine, Helicopter, Rowboat, Speedboat, SportsCar, Truck, Vehicle, Yacht (You may add additional objects if it helps your organization.) Page 10 of 10