Name: CS 159 Practice Final Fall 2015
|
|
- Giles Holt
- 6 years ago
- Views:
Transcription
1 Name: CS 159 Practice Final Fall 2015
2 CS 159, Fall 2015 Final Exam Section 02 Page 2 of Choose the best answer for each of the following multiple choice questions. (a) (2 points) What will happen when the following lines of code are executed? String [] names = new String [3]; System. out. println (" Length of 2: " + names [2]. length ()); An ArrayIndexOutOfBoundsException exception will be thrown. A NullPointerException exception will be thrown. "Length of 2: 0" will be printed. "Length of 2: 2" will be printed. (b) (2 points) What is the type of names[2] after the following line of code executes? String [][] names = new String [3][2]; String String[] String[][] Accessing numbers[2] will result in an ArrayIndexOutOfBoundsException. (c) (2 points) Which of the following best describes the class java.io.file? File is a subclass of OutputStream. A File object provides open, close and write methods that may be used to modify files. A File object represents the location of a file, including the file name and the directory path. All of the above. (d) (2 points) Which of the following could be a good reason to use an abstract class rather than an interface? You wish to declare a common set of methods that should be implemented by several otherwise unrelated classes. Logically, the class should not be instantiated, but you want to avoid code duplication by allowing other classes to inherit methods implemented in the class. You want to create your own type-safe collection, something like: YourCollection<T>. Any of the above. (e) (2 points) Which of the following would be a good reason to use an iterator directly (rather than using a traditional for loop or an enhanced for loop). Iterators can be used to remove elements from a collection during iteration. Iterator-based loops result in cleaner code that is easier to read. Iterator-based loops are usually the fastest way to iterate through a collection. There is no good reason to use an iterator directly. Iterators only exist to support the enhanced for loop. (f) (2 points) Which of the following operations is likely to execute significantly faster if mylist is a LinkedList rather than an ArrayList. mylist.contains(a); mylist.get(i); mylist.remove(0); mylist.remove(mylist.size() - 1); Page 2
3 CS 159, Fall 2015 Final Exam Section 02 Page 3 of (a) (4 points) Draw a UML diagram corresponding to the accompanying Named interface and the Employee, Hourly, Salaried and Movie classes. For full credit, you must use correct UML syntax, including arrow types, etc. Feel free to explicitly label italicized text. YOU DO NOT NEED TO INCLUDE INSTANCE VARIABLES OR METHODS IN YOUR DI- AGRAM. (b) (2 points) There are only six valid movie ratings in the United States: G, PG, PG- 13, R, NC-17 and NR. Given this fact, how could the design of the Movie class be improved? (c) (2 points) Read over the attached interface and classes. There is at least one opportunity to improve this design by reducing code duplication without changing the existing class hierarchy and without changing the functionality. What change should be made? Page 3
4 CS 159, Fall 2015 Final Exam Section 02 Page 4 of Consider the following UML diagram. (a) (2 points) Write the Encryptable interface in Java. (b) (4 points) Write the AudioFile class in Java. Page 4
5 CS 159, Fall 2015 Final Exam Section 02 Page 5 of (a) (8 points) Given the attached Movie class, what will be printed by the following method? public class ReferenceMain public static void main ( String [] args ) Movie [] movies = new Movie [3]; Movie first, second ; first = new Movie (2003, " Elf "); movies [0] = first ; first. setrating ("R"); movies [1] = first ; first = new Movie (2012, " Ted "); second = first ; second. setrating ("PG -13 "); movies [2] = new Movie (1988, first. getname () + " 2"); second. setrating ("PG"); for ( Movie curmovie : movies ) System. out. println ( curmovie. tostring ()); System. out. println ( first. tostring ()); System. out. println ( second. tostring ()); (b) (4 points) Now assume that the Movie class has been modified to make the rating field static: public static String rating; What will be printed by the method above given this modification? Page 5
6 CS 159, Fall 2015 Final Exam Section 02 Page 6 of (8 points) Given the attached Employee, Hourly, and Salaried classes, what will be printed when the following main method is executed? public class BusinessDriver public static void main ( String [] args ) Employee [] workers = new Employee [2]; Salaried boss ; Hourly tech ; boss = new Salaried (" Lovelace, Ada ", , 2003); workers [0] = boss ; tech = new Hourly (" Hopper, Grace ", 15.00, 2007); tech. sethoursworked (3); workers [1] = tech ; printpayinfo ( boss ); printpayinfo ( tech ); for ( int i = 0; i < workers. length ; i ++) printpayinfo ( workers [i ]); public static void printpayinfo ( Employee employee ) System. out. print (" Employee Pay : "); System. out. println ( employee. getname () + ", " + employee. getpay ()); public static void printpayinfo ( Hourly employee ) System. out. print (" Hourly Pay : "); System. out. println ( employee. getname () + ": " + employee. getpay ()); public static void printpayinfo ( Salaried employee ) System. out. print (" Salary Pay : "); System. out. println ( employee. getname () + ": " + employee. getpay ()); Page 6
7 CS 159, Fall 2015 Final Exam Section 02 Page 7 of (6 points) Given the attached files and the following main method: public class CompileDriver public static void main ( String [] args ) Named named ; Employee worker ; Hourly cook ; Salaried manager ; worker = new Salaried (" Jim ", ); // Code instantiating named, cook and manager not shown... // The code in the questions below will be inserted here... Indicate which of the following statements will: not compile (N), compile but generate an exception at runtime (C+X), or compile and run without generating an exception (C+R). You may assume that the named, cook and manager variables have been instantiated with appropriate types. Each statement should be considered independently. (a) (b) (c) (d) (e) (f) (g) (h) (i) (j) (k) (l) named = new Movie(1999, "The Matrix"); named = new Employee("Bob Doe"); named = worker; worker = cook; manager = worker; cook = named; String name = named.getname(); double pay = cook.getpay(); worker.sethours(5.0); named.name = "Bill"; cook = (Hourly)worker; manager = (Salaried)worker; Page 7
8 CS 159, Fall 2015 Final Exam Section 02 Page 8 of (10 points) Given the attached Movie class, write a statement (or statements) that does each of the following. Where possible, your answers must be type-safe. (a) Declares variables named forkids and gmovies as ArrayLists of Movie objects. (b) Instantiates forkids. (c) Declares a variable named ratingmap as a HashMap in which the keys are String objects and forkids could be a value. (d) Instantiates ratingmap. (e) Adds forkids to ratingmap using the key "G". (f) Declares a variable named it as an Iterator of Movie objects. (g) Gets the value in ratingmap with the key "G" and assigns it to the variable named gmovies. (h) Gets an Iterator of Movie objects from gmovies and assigns it to the variable named it. (i) Declares a variable named best as a Movie. (j) Gets the last Movie in forkids and assigns it to the variable best. (Your statement should not use the iterator object.) (k) Prints the name and rating (separated by a space) for each movie accessible through the iterator it. Page 8
9 CS 159, Fall 2015 Final Exam Section 02 Page 9 of Consider the following recursive method: public static String func02 ( String s) String result ; if ( s. length () == 0) result = "_"; else String first = s. substring (0, 1); String rest = s. substring (1, s. length ()); result = "*" + first + func02 ( rest ) + first + "*"; return result ; (a) (3 points) Draw the activation records that will result from the following call to func1. Each activation record should be drawn as a box containing the local value of s. String answer = func02 (" pan "); (b) (3 points) What value will be stored in answer after the line of code above has completed? Page 9
10 CS 159, Fall 2015 Final Exam Section 02 Page 10 of Complete the recursive method described blow. (This question is borrowed from CodingBat.) We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows. triangle(0) 0 triangle(1) 1 triangle(2) 3 public int triangle ( int rows ) Page 10
11 CS 159, Fall 2015 Final Exam Section 02 Page 11 of (8 points) Complete the following method of the Movie class so that it conforms to the Javadoc comments. /** * Return an ArrayList of sequels for this movie. Sequels are named by appending * an appropriate number to the name of the original movie. The first sequel * must be named using Roman numerals, while all subsequent sequels must be * named using Arabic numerals. For example, the sequels for " Rocky " must * be named " Rocky II", " Rocky 3", " Rocky 4" etc. * * Sequels appear at two - year intervals. For example, the movie " Rocky " * released in 1976 would have sequels released in 1978, 1980, etc. * All sequels must have the same rating as the original movie. * howmany How many sequels to create An ArrayList containing all sequels IllegalArgumentException If the number of sequels is less than 1 * or more than 6. */ public ArrayList < Movie > sequels ( int howmany ) Page 11
12 CS 159, Fall 2015 Final Exam Section 02 Page 12 of 16 Page 12
13 public interface Named String getname (); public class Movie implements Named public int year ; public String name ; public String rating ; public Movie ( int year, String name ) this. year = year ; this. name = name ; rating = "NR"; public int getyear () return year ; public String getname () return name ; public String getrating () return rating ; public void setrating ( String rating ) this. rating = rating ; public ArrayList < Movie > sequels ( int howmany ) // Code not shown. public String tostring () return name + " (" + year + ") " + rating ; 13
14 public abstract class Employee implements Named protected String name ; public Employee ( String name ) this. name = name ; public String getname () return name ; public double getpay () return -1.0; public class Salaried extends Employee public static final int PAY_ PERIODS = 12; private double salary ; private int startyear ; public Salaried ( String name, double salary, int startyear ) super ( name ); this. salary = salary ; this. startyear = startyear ; public double getpay () return salary / PAY_ PERIODS ; public double getsalary () return salary ; public void setsalary ( double salary ) this. salary = salary ; public int getstartyear () return startyear ; 14
15 public class Hourly extends Employee private double hoursworked ; private double payrate ; private final int startyear ; public Hourly ( String name, double payrate, int startyear ) super ( name ); this. payrate = payrate ; this. startyear = startyear ; hoursworked = 0; public double getpay () return hoursworked * payrate ; public void sethoursworked ( double hoursworked ) this. hoursworked = hoursworked ; public void setpayrate ( double payrate ) this. payrate = payrate ; public int startyear () return startyear ; public String tostring () return " Name : " + name + " Rate : " + payrate ; 15
16 16
Name: CS 159 Practice Final Fall 2015
Name: CS 159 Practice Final Fall 2015 CS 159, Fall 2015 Final Exam Section 02 Page 2 of 17 1. Choose the best answer for each of the following multiple choice questions. (a) (2 points) What will happen
More informationCS111: PROGRAMMING LANGUAGE II
1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 8(a): Abstract Classes Lecture Contents 2 Abstract base classes Concrete classes Dr. Amal Khalifa, 2014 Abstract Classes and Methods
More informationJava Programming Lecture 7
Java Programming Lecture 7 Alice E. Fischer Feb 16, 2015 Java Programming - L7... 1/16 Class Derivation Interfaces Examples Java Programming - L7... 2/16 Purpose of Derivation Class derivation is used
More informationRelationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.
CSE 143 Java Object & Class Relationships Inheritance Reading: Ch. 9, 14 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches
More informationCS159 Midterm #1 Review
Name: CS159 Midterm #1 Review 1. Choose the best answer for each of the following multiple choice questions. (a) What is the effect of declaring a class member to be static? It means that the member cannot
More informationPractice exam for CMSC131-04, Fall 2017
Practice exam for CMSC131-04, Fall 2017 Q1 makepalindrome - Relevant topics: arrays, loops Write a method makepalidrome that takes an int array, return a new int array that contains the values from the
More informationRelationships Between Real Things CSC 143. Common Relationship Patterns. Composition: "has a" CSC Employee. Supervisor
CSC 143 Object & Class Relationships Inheritance Reading: Ch. 10, 11 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches dog
More informationJava Review: Objects
Outline Java review Abstract Data Types (ADTs) Interfaces Class Hierarchy, Abstract Classes, Inheritance Invariants Lists ArrayList LinkedList runtime analysis Iterators Java references 1 Exam Preparation
More informationRelationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor
CSE 143 Object & Class Relationships Inheritance Reading: Ch. 9, 14 Relationships Between Real Things Man walks dog Dog strains at leash Dog wears collar Man wears hat Girl feeds dog Girl watches dog Dog
More informationJava and OOP. Part 3 Extending classes. OOP in Java : W. Milner 2005 : Slide 1
Java and OOP Part 3 Extending classes OOP in Java : W. Milner 2005 : Slide 1 Inheritance Suppose we want a version of an existing class, which is slightly different from it. We want to avoid starting again
More informationCSC 1351: Final. The code compiles, but when it runs it throws a ArrayIndexOutOfBoundsException
VERSION A CSC 1351: Final Name: 1 Interfaces, Classes and Inheritance 2 Basic Data Types (arrays, lists, stacks, queues, trees,...) 2.1 Does the following code compile? If it does not, how can it be fixed?
More informationCSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015
CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015 Name: This exam consists of 6 problems on the following 7 pages. You may use your single-sided handwritten 8 ½ x 11 note sheet during
More informationCS159. Nathan Sprague
CS159 Nathan Sprague What s wrong with the following code? 1 /* ************************************************** 2 * Return the mean, or -1 if the array has length 0. 3 ***************************************************
More informationJava How to Program, 8/e
Java How to Program, 8/e Polymorphism Enables you to program in the general rather than program in the specific. Polymorphism enables you to write programs that process objects that share the same superclass
More informationChapter 2a Class Relationships
Data Structures for Java William H. Ford William R. Topp Chapter 2a Class Relationships Bret Ford 2005, Prentice Hall Wrapper Classes Convert a value of primitive type to an object. Supply methods to access
More informationCST141--Inheritance 2
- employeeid - hoursworked - checknumber payrate -+ employeeid setchecknumber() -+ hoursworked setemployeeid() -+ payrate sethoursworked() ed-oriented and Inheritance + setchecknumber() setpayrate() CST141
More informationThe software crisis. code reuse: The practice of writing program code once and using it in many contexts.
Inheritance The software crisis software engineering: The practice of conceptualizing, designing, developing, documenting, and testing largescale computer programs. Large-scale projects face many issues:
More informationBig software. code reuse: The practice of writing program code once and using it in many contexts.
Inheritance Big software software engineering: The practice of conceptualizing, designing, developing, documenting, and testing largescale computer programs. Large-scale projects face many issues: getting
More informationModule Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1
UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2015-16 PROGRAMMING 1 CMP-4008Y Time allowed: 2 hours Section A (Attempt all questions: 80 marks) Section B (Attempt one
More informationThe software crisis. code reuse: The practice of writing program code once and using it in many contexts.
Inheritance The software crisis software engineering: The practice of conceptualizing, designing, developing, documenting, and testing largescale computer programs. Large-scale projects face many issues:
More informationCOMPUTER SCIENCE DEPARTMENT PICNIC. Operations. Push the power button and hold. Once the light begins blinking, enter the room code
COMPUTER SCIENCE DEPARTMENT PICNIC Welcome to the 2016-2017 Academic year! Meet your faculty, department staff, and fellow students in a social setting. Food and drink will be provided. When: Saturday,
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationSSE3052: Embedded Systems Practice
SSE3052: Embedded Systems Practice Minwoo Ahn minwoo.ahn@csl.skku.edu Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE3052: Embedded Systems Practice, Spring 2018, Jinkyu Jeong
More informationCS159. Nathan Sprague
CS159 Nathan Sprague What s wrong with the following code? 1 /* ************************************************** 2 * Return the maximum, or Integer. MIN_VALUE 3 * if the array has length 0. 4 ***************************************************
More informationChapter 7. Inheritance
Chapter 7 Inheritance Introduction to Inheritance Inheritance is one of the main techniques of objectoriented programming (OOP) Using this technique, a very general form of a class is first defined and
More informationPractice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course
: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course 1. Given the following hierarchy: class Alpha {... class Beta extends Alpha {... class Gamma extends Beta {... In what order
More informationCS 209 Sec. 52 Spring, 2006 Lab 5: Classes Instructor: J.G. Neal
CS 209 Sec. 52 Spring, 2006 Lab 5: Classes Instructor: J.G. Neal Objectives. To gain experience with: 1. The definition and use of a class to represent a real-world type of entity (an employee). 2. Adding
More informationAdvanced Java Concepts Unit 2: Linked Lists.
Advanced Java Concepts Unit 2: Linked Lists. The List interface defines the structure of a linear collection. Here are some of its methods. boolean add( E element ) Appends the element to the end of the
More informationCS 251 Intermediate Programming Inheritance
CS 251 Intermediate Programming Inheritance Brooke Chenoweth University of New Mexico Spring 2018 Inheritance We don t inherit the earth from our parents, We only borrow it from our children. What is inheritance?
More informationCST141 Thinking in Objects Page 1
CST141 Thinking in Objects Page 1 1 2 3 4 5 6 7 8 Object-Oriented Thinking CST141 Class Abstraction and Encapsulation Class abstraction is the separation of class implementation from class use It is not
More informationCS 11 java track: lecture 3
CS 11 java track: lecture 3 This week: documentation (javadoc) exception handling more on object-oriented programming (OOP) inheritance and polymorphism abstract classes and interfaces graphical user interfaces
More informationpublic static boolean isoutside(int min, int max, int value)
See the 2 APIs attached at the end of this worksheet. 1. Methods: Javadoc Complete the Javadoc comments for the following two methods from the API: (a) / @param @param @param @return @pre. / public static
More informationSoftware and Programming 1
Software and Programming 1 Week 9 Lab - Use of Classes and Inheritance 8th March 2018 SP1-Lab9-2018.ppt Tobi Brodie (Tobi@dcs.bbk.ac.uk) 1 Lab 9: Objectives Exercise 1 Student & StudentTest classes 1.
More informationCSCI 200 Lab 2 Inheritance, Polymorphism & Data Streams
CSCI 200 Lab 2 Inheritance, Polymorphism & Data Streams In this lab you will write a set of simple Java interfaces and classes that use inheritance and polymorphism. You will also write code that uses
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationModule Contact: Dr Taoyang Wu, CMP Copyright of the University of East Anglia Version 1
UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2016-17 PROGRAMMING FOR NON-SPECIALISTS CMP-5020B Time allowed: 2 hours Section A (Attempt all questions: 80 marks) Section
More informationProgramming in C# Inheritance and Polymorphism
Programming in C# Inheritance and Polymorphism C# Classes Classes are used to accomplish: Modularity: Scope for global (static) methods Blueprints for generating objects or instances: Per instance data
More informationTeenCoder : Java Programming (ISBN )
TeenCoder : Java Programming (ISBN 978-0-9887070-2-3) and the AP * Computer Science A Exam Requirements (Alignment to Tennessee AP CS A course code 3635) Updated March, 2015 Contains the new 2014-2015+
More informationMidterm Exam CS 251, Intermediate Programming March 6, 2015
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
More informationPieter van den Hombergh Thijs Dorssers Stefan Sobek. January 11, 2018
Inheritance and Inheritance and Pieter van den Hombergh Thijs Dorssers Stefan Sobek Java Inheritance Example I Visibility peekabo Constructors Fontys Hogeschool voor Techniek en Logistiek January 11, 2018
More informationObject Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming
Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions and
More informationPrelim 1. Solution. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer
Prelim 1. Solution CS 2110, 14 March 2017, 7:30 PM 1 2 3 4 5 Total Question Name Short answer OO Recursion Loop invariants Max 1 36 33 15 15 100 Score Grader 1. Name (1 point) Write your name and NetID
More informationObject Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.
CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java
More informationCS 113 PRACTICE FINAL
CS 113 PRACTICE FINAL There are 13 questions on this test. The value of each question is: 1-10 multiple choice (4 pt) 11-13 coding problems (20 pt) You may get partial credit for questions 11-13. If you
More informationCS111: PROGRAMMING LANGUAGE II
1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 8(b): Abstract classes & Polymorphism Lecture Contents 2 Abstract base classes Concrete classes Polymorphic processing Dr. Amal Khalifa,
More informationMidterm Exam CS 251, Intermediate Programming March 12, 2014
Midterm Exam CS 251, Intermediate Programming March 12, 2014 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible
More informationCS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016
General instructions: CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016 Please wait to open this exam booklet until you are told to do so. This examination booklet has 13 pages.
More informationPASS4TEST IT 인증시험덤프전문사이트
PASS4TEST IT 인증시험덤프전문사이트 http://www.pass4test.net 일년동안무료업데이트 Exam : 1z0-809 Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z0-809 Exam's Question and Answers 1 from
More informationRules and syntax for inheritance. The boring stuff
Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for
More informationCS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?
CS6501 - Internet programming Unit- I Part - A 1 Define Java. Java is a programming language expressly designed for use in the distributed environment of the Internet. It was designed to have the "look
More informationCISC 3115 Modern Programming Techniques Spring 2018 Section TY3 Exam 2 Solutions
Name CISC 3115 Modern Programming Techniques Spring 2018 Section TY3 Exam 2 Solutions 1. a. (25 points) A rational number is a number that can be represented by a pair of integers a numerator and a denominator.
More informationCS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance
CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance Handout written by Julie Zelenski, updated by Jerry. Inheritance is a language property most gracefully supported by the object-oriented
More informationBrief Summary of Java
Brief Summary of Java Java programs are compiled into an intermediate format, known as bytecode, and then run through an interpreter that executes in a Java Virtual Machine (JVM). The basic syntax of Java
More information1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'
Practice questions: 1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 2. Will System.out.println((char)4) display 4? a. Yes b. No 3. The expression "Java
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions
More informationCSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community
CSCI-12 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Provide a detailed explanation of what the following code does: 1 public boolean checkstring
More information1.00 Lecture 13. Inheritance
1.00 Lecture 13 Inheritance Reading for next time: Big Java: sections 10.5-10.6 Inheritance Inheritance allows you to write new classes based on existing (super or base) classes Inherit super class methods
More informationP2: Advanced Java & Exam Preparation
P2: Advanced Java & Exam Preparation Claudio Corrodi May 18 2018 1 Java 8: Default Methods public interface Addressable { public String getstreet(); public String getcity(); public String getfulladdress();
More informationExam Duration: 2hrs and 30min Software Design
Exam Duration: 2hrs and 30min. 433-254 Software Design Section A Multiple Choice (This sample paper has less questions than the exam paper The exam paper will have 25 Multiple Choice questions.) 1. Which
More informationC18a: Abstract Class and Method
CISC 3115 TY3 C18a: Abstract Class and Method Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/31/2018 CUNY Brooklyn College 1 Outline Recap Inheritance and polymorphism Abstract
More informationPieter van den Hombergh Thijs Dorssers Stefan Sobek. February 10, 2017
Inheritance and Inheritance and Pieter van den Hombergh Thijs Dorssers Stefan Sobek Fontys Hogeschool voor Techniek en Logistiek February 10, 2017 /FHTenL Inheritance and February 10, 2017 1/45 Topics
More informationA A B U n i v e r s i t y
A A B U n i v e r s i t y Faculty of Computer Sciences O b j e c t O r i e n t e d P r o g r a m m i n g Week 10: I n h e r i t a n c e Asst. Prof. Dr. M entor Hamiti mentor.hamiti@universitetiaab.com
More informationAbout this sample exam:
About this sample exam: You may and SHOULD work through this exam yourself and discuss you answers with others. To find out the right answers to questions, type in the code to a compiler and run it. You
More informationCSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed
CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What would
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationOVERRIDING. 7/11/2015 Budditha Hettige 82
OVERRIDING 7/11/2015 (budditha@yahoo.com) 82 What is Overriding Is a language feature Allows a subclass or child class to provide a specific implementation of a method that is already provided by one of
More informationBBM 102 Introduction to Programming II Spring Inheritance
BBM 102 Introduction to Programming II Spring 2018 Inheritance 1 Today Inheritance Notion of subclasses and superclasses protected members UML Class Diagrams for inheritance 2 Inheritance A form of software
More informationCOE318 Lecture Notes Week 10 (Nov 7, 2011)
COE318 Software Systems Lecture Notes: Week 10 1 of 5 COE318 Lecture Notes Week 10 (Nov 7, 2011) Topics More about exceptions References Head First Java: Chapter 11 (Risky Behavior) The Java Tutorial:
More informationCS105 C++ Lecture 7. More on Classes, Inheritance
CS105 C++ Lecture 7 More on Classes, Inheritance " Operator Overloading Global vs Member Functions Difference: member functions already have this as an argument implicitly, global has to take another parameter.
More informationPractice problem on defining and using Class types. Part 4.
CS180 Programming Fundamentals Practice problem on defining and using Class types. Part 4. Implementing object associations: Applications typically consist of collections of objects of different related
More informationExamination Questions Midterm 1
CS1102s Data Structures and Algorithms 10/2/2010 Examination Questions Midterm 1 This examination question booklet has 9 pages, including this cover page, and contains 15 questions. You have 40 minutes
More informationJava classes cannot extend multiple superclasses (unlike Python) but classes can implement multiple interfaces.
CSM 61B Abstract Classes & Interfaces Spring 2017 Week 5: February 13, 2017 1 An Appealing Appetizer 1.1 public interface Consumable { public void consume (); public abstract class Food implements Consumable
More informationSuper-Classes and sub-classes
Super-Classes and sub-classes Subclasses. Overriding Methods Subclass Constructors Inheritance Hierarchies Polymorphism Casting 1 Subclasses: Often you want to write a class that is a special case of an
More informationCSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2013
CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2013 Name: This exam consists of 5 problems on the following 7 pages. You may use your single-side hand-written 8 ½ x 11 note sheet during
More informationIntroduction to Object-Oriented Programming
Polymorphism 1 / 19 Introduction to Object-Oriented Programming Today we ll learn how to combine all the elements of object-oriented programming in the design of a program that handles a company payroll.
More informationASSIGNMENT 5 Objects, Files, and a Music Player
ASSIGNMENT 5 Objects, Files, and a Music Player COMP-202A, Fall 2009, All Sections Due: Thursday, December 3, 2009 (23:55) You MUST do this assignment individually and, unless otherwise specified, you
More informationCoverage of Part 2. A Brief Introduction to Java for C++ Programmers: Part 2. import: using packages
Coverage of Part 2 A Brief Introduction to Java for C++ Programmers: Part 2 ENGI 5895: Software Design Andrew Vardy Faculty of Engineering & Applied Science Memorial University of Newfoundland This second
More information15CS45 : OBJECT ORIENTED CONCEPTS
15CS45 : OBJECT ORIENTED CONCEPTS QUESTION BANK: What do you know about Java? What are the supported platforms by Java Programming Language? List any five features of Java? Why is Java Architectural Neutral?
More informationCompuScholar, Inc. 9th - 12th grades
CompuScholar, Inc. Alignment to the College Board AP Computer Science A Standards 9th - 12th grades AP Course Details: Course Title: Grade Level: Standards Link: AP Computer Science A 9th - 12th grades
More informationCSIS 10A Practice Final Exam Solutions
CSIS 10A Practice Final Exam Solutions 1) (5 points) What would be the output when the following code block executes? int a=3, b=8, c=2; if (a < b && b < c) b = b + 2; if ( b > 5 a < 3) a = a 1; if ( c!=
More informationWeek 4, Wednesday (Spring 2015). Dr. Yoder. Sec 051. Page 1 of 5
CS2852 Exam 1 Name: No note-sheets, calculators, or other study aids on this exam. Write your initials at the top of each page except this one. Read through the whole exam before you get started. Have
More informationCSE 143 Au03 Final Exam Page 1 of 15
CSE 143 Au03 Final Exam Page 1 of 15 Reference information about many standard Java classes appears at the end of the test. You might want to tear off those pages to make them easier to refer to while
More informationASSIGNMENT 5 Objects, Files, and More Garage Management
ASSIGNMENT 5 Objects, Files, and More Garage Management COMP-202B, Winter 2010, All Sections Due: Wednesday, April 14, 2009 (23:55) You MUST do this assignment individually and, unless otherwise specified,
More informationFundamentals of Object Oriented Programming
INDIAN INSTITUTE OF TECHNOLOGY ROORKEE Fundamentals of Object Oriented Programming CSN- 103 Dr. R. Balasubramanian Associate Professor Department of Computer Science and Engineering Indian Institute of
More informationCSC Java Programming, Fall Java Data Types and Control Constructs
CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference
More information16-Dec-10. Consider the following method:
Boaz Kantor Introduction to Computer Science IDC Herzliya Exception is a class. Java comes with many, we can write our own. The Exception objects, along with some Java-specific structures, allow us to
More informationCSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2014
CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2014 Name: This exam consists of 5 problems on the following 6 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet
More informationCS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:
CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : If a child overrides
More informationInheritance and Interfaces
Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical
More informationCS Programming Language Java. Fall 2004 Sept. 29
CS3101-3 Programming Language Java Fall 2004 Sept. 29 Road Map today Java review Homework review Exception revisited Containers I/O What is Java A programming language A virtual machine JVM A runtime environment
More informationMidterm 1 Review Document
Midterm 1 Review Document CS61B Fall 2016 Antares Chen Introduction This document is meant to provide you supplementary practice questions for the upcoming midterm. It reflects all material that you will
More informationImplements vs. Extends When Defining a Class
Implements vs. Extends When Defining a Class implements: Keyword followed by the name of an INTERFACE Interfaces only have method PROTOTYPES You CANNOT create on object of an interface type extends: Keyword
More informationConsiderations. New components can easily be added to a design.
Composite Pattern Facilitates the composition of objects into tree structures that represent part-whole hierarchies. These hierarchies consist of both primitive and composite objects. Considerations Clients
More informationSelf-review Questions
7Class Relationships 106 Chapter 7: Class Relationships Self-review Questions 7.1 How is association between classes implemented? An association between two classes is realized as a link between instance
More informationQuestion 0. (1 point) Write the correct ID of the section you normally attend on the cover page of this exam if you have not already done so.
CSE 143 Sp04 Midterm 2 Page 1 of 10 Reference information about some standard Java library classes appears on the last pages of the test. You can tear off these pages for easier reference during the exam
More informationCS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM
CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM Objectives Defining a wellformed method to check class invariants Using assert statements to check preconditions,
More informationITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!
ITCertMaster Safe, simple and fast. 100% Pass guarantee! Exam : 1z0-853 Title : Java Standard Edition 5 Programmer Certified Professional Exam Vendor : Oracle Version : DEMO Get Latest & Valid 1Z0-853
More informationLogistics. Final Exam on Friday at 3pm in CHEM 102
Java Review Logistics Final Exam on Friday at 3pm in CHEM 102 What is a class? A class is primarily a description of objects, or instances, of that class A class contains one or more constructors to create
More informationChapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,
Chapter 11 Inheritance and Polymorphism 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design
More information