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

Size: px
Start display at page:

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

Transcription

1 CIS 265/506 Exam1 Spring 2012 Prof. V. Matos Exam Last Name First Name: MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Suppose x = 1, y = -1, and z = 1. What is the printout of the following statement? 1) if (x > 0) if (y > 0) System.out.println("x > 0 and y > 0"); else if (z > 0) System.out.println("x < 0 and z > 0"); A) x < 0 and z < 0; B) x < 0 and z > 0; C) x > 0 and y > 0; D) no printout. 2) The following code displays. 2) double temperature = 50; if (temperature >= 100) System.out.println("too hot"); else if (temperature <= 40) System.out.println("too cold"); else System.out.println("just right"); A) too hot B) too hot too cold just right C) just right D) too cold 3) Analyze the following code: 3) Code 1: boolean even; if (number % 2 == 0) even = true; else even = false; Code 2: boolean even = (number % 2 == 0); A) Code 2 has compile errors. B) Both Code 1 and Code 2 have compile errors. C) Code 1 has compile errors. D) Both Code 1 and Code 2 are correct, but Code 2 is better. 4) Suppose income is 4001, what is the output of the following code: 4) if (income > 3000) { System.out.println("Income is greater than 3000"); else if (income > 4000) { System.out.println("Income is greater than 4000"); A) Income is greater than 4000 B) Income is greater than 4000 followed by Income is greater than 3000 C) Income is greater than 3000 followed by Income is greater than 4000 D) Income is greater than 3000 E) no output

2 5) Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative? A) 1 < x < 100 && x < 0 B) (1 > x > 100) (x < 0) C) ((x < 100) && (x > 1)) && (x < 0) D) ((x < 100) && (x > 1)) (x < 0) 6) What is the output of the following code? 5) 6) char ch = 'F'; if (ch >= 'A' && ch <= 'Z') System.out.println(ch); A) F B) f C) F f D) nothing 7) What is y after the following statement is executed? 7) x = 0; y = (x > 0)? 10 : -10; A) 0 B) 20 C) -10 D) 10 E) Illegal expression 8) How many times will the following code print "Welcome to Java"? 8) int count = 0; while (count++ < 10) { System.out.println("Welcome to Java"); A) 11 B) 8 C) 0 D) 9 E) 10 9) What is the output for y? 9) int y = 0; for (int i = 0; i<10; ++i) { y += i; System.out.println(y); A) 12 B) 10 C) 45 D) 11 E) 13 10) What is i after the following for loop? 10) int y = 0; for (int i = 0; i<10; ++i) { y += i; A) 9 B) 11 C) 10 D) undefined 11) What is the number of iterations in the following loop: 11) for (int i = 1; i < n; i++) { // iteration A) 2*n B) n + 1 C) n - 1 D) n

3 12) Analyze the following code: 12) class Test { System.out.println(xmethod(5)); public static int xmethod(int n, long t) { System.out.println("int"); return n; public static long xmethod(long n) { System.out.println("long"); return n; A) The program displays long followed by 5. B) The program displays int followed by 5. C) The program runs fine but displays things other than 5. D) The program does not compile because the compiler cannot distinguish which xmethod to invoke. 13) If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5, list[1] is. 13) A) 5.5 B) 2.0 C) 3.4 D) 3.4 E) undefined 14) If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5, the highest index in array list is. A) 2 B) 3 C) 1 D) 4 E) 0 14) 15) How many elements are in array double[ ] list = new double[5]? 15) A) 6 B) 5 C) 4 D) 0 16) In the following code, what is the printout for list2? 16) 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 < list2.length; i++) System.out.print(list2[i] + " "); A) B) C) D) ) When you pass an array to a method, the method receives. 17) A) a copy of the first element B) a copy of the array C) the reference of the array D) the length of the array

4 18) Show the output of the following code: 18) int[ ] x = {1, 2, 3, 4, 5; increase(x); int[ ] y = {1, 2, 3, 4, 5; increase(y[0]); System.out.println(x[0] + " " + y[0]); public static void increase(int[ ] x) { for (int i = 0; i < x.length; i++) x[i]++; public static void increase(int y) { y++; A) 1 1 B) 0 0 C) 1 2 D) 2 1 E) ) When you return an array from a method, the method returns. 19) A) a copy of the array B) a copy of the first element C) the length of the array D) the reference of the array 20) is a construct that defines objects of the same type. 20) A) A class B) A method C) An object D) A data field 21) An object is an instance of a. 21) A) data B) class C) program D) method 22) is invoked to create an object. 22) A) The main method B) A method with the void return type C) A method with a return type D) A constructor 23) Analyze the following code. 23) int x; public Test(String t) { System.out.println("Test"); Test test = new Test(); System.out.println(test.x); A) The program has a compile error because System.out.println method cannot be invoked from the constructor. B) The program has a compile error because Test does not have a default constructor. 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 x has not been initialized.

5 24) Which is the advantage of encapsulation? 24) A) It changes a class's contract without changing the implementation and causes no consequential changes to other code. B) Only public methods are needed. C) Making the class final causes no consequential changes to other code. D) It changes the implementation without changing a class's contract and causes no consequential changes to other code. 25) When invoking a method with an object argument, is passed. 25) A) the contents of the object B) the object is copied, then the reference of the copied object C) a copy of the object D) the reference of the object 26) Suppose s is a string with the value "java". What will be assigned to x if you execute the following code? 26) char x = s.charat(4); A) 'v' B) 'a' C) Nothing will be assigned to x, because the execution causes the runtime error StringIndexOutofBoundsException. 27) What is the output of the following code? 27) String s1 = new String("Welcome to Java!"); String s2 = new String("Welcome to Java!"); if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); A) s1 and s2 reference to different String objects B) s1 and s2 reference to the same String object 28) What is the output of the following code? 28) String s1 = new String("Welcome to Java!"); String s2 = new String("Welcome to Java!"); if (s1.equals(s2)) System.out.println("s1 and s2 have the same contents"); else System.out.println("s1 and s2 have different contents"); A) s1 and s2 have the same contents B) s1 and s2 have different contents

6 29) What is the output of running class C? 29) class A { public A() { System.out.println( "The default constructor of A is invoked"); class B extends A { public B() { System.out.println( "The default constructor of B is invoked"); public class C { B b = new B(); A) "The default constructor of B is invoked" B) "The default constructor of A is invoked" C) "The default constructor of A is invoked""the default constructor of B is invoked" D) Nothing displayed E) "The default constructor of B is invoked""the default constructor of A is invoked" 30) Analyze the following code: 30) B b = new B(); b.m(5); System.out.println("i is " + b.i); class A { int i; public void m(int i) { this.i = i; class B extends A { public void m(string s) { A) The method m is not overridden in B. B inherits the method m from A and defines an overloaded method m in B. B) The program has a runtime error on b.i, because i is not accessible from b. C) The program has a compilation error, because m is overridden with a different signature in B. D) The program has a compilation error, because b.m(5) cannot be invoked since the method m(int) is hidden in B.

7 (20 pts) Part 2. Java Programming CIS265/506 Exam1 Spring 2012 Last Name: First name: This problem is based on the GeometricObject Rectangle Circle classes discussed in class, see diagram. Assume you are given an ArrayList holding various Rectangle objects. Write a method to be added to the Driver class to find the location of the rectangle having the largest side (either height or width side). The method returns the position of the selected rectangle in the list, or -1 when the list is empty. The method s signature is given below. public static int findpositionofrectanglewithlargestside ( ArrayList list ) {

8

9 1) B 2) C 3) D 4) D 5) D 6) A 7) C 8) E 9) C 10) D 11) C 12) A 13) B 14) B 15) B 16) B 17) C 18) D 19) D 20) A 21) B 22) D 23) B 24) D 25) D 26) C 27) A 28) A 29) C 30) A

CIS 265 Summer 2015 Exam 1 First Name Last Name

CIS 265 Summer 2015 Exam 1 First Name Last Name CIS 265 Summer 2015 Exam 1 First Name Last Name ID MULTIPLE CHOICE. (30pts - 3 pts each) Choose the one alternative that best completes the statement or answers the question. 1) Which of the following

More information

Questions Answer Key Questions Answer Key Questions Answer Key

Questions Answer Key Questions Answer Key Questions Answer Key Benha University Term: 2 nd (2013/2014) Class: 2 nd Year Students Subject: Object Oriented Programming Faculty of Computers & Informatics Date: 26/4/2014 Time: 1 hours Exam: Mid-Term (A) Name:. Status:

More information

Questions Answer Key Questions Answer Key Questions Answer Key

Questions Answer Key Questions Answer Key Questions Answer Key Benha University Term: 2 nd (2013/2014) Class: 2 nd Year Students Subject: Object Oriented Programming Faculty of Computers & Informatics Date: 26/4/2014 Time: 1 hours Exam: Mid-Term (C) Name:. Status:

More information

Practice Questions for Chapter 9

Practice Questions for Chapter 9 Practice Questions for Chapter 9 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) An object is an instance of a. 1) A) program B) method C) class

More information

Practice for Chapter 11

Practice for Chapter 11 Practice for Chapter 11 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Object-oriented programming allows you to derive new classes from existing

More information

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

CS2401 QUIZ 5 February 26, questions / 20 points / 20 minutes NAME:.. 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

More information

CIS265 - Spring Exam 2 First Name Last Name CSU#

CIS265 - Spring Exam 2 First Name Last Name CSU# CIS265 - Spring 2013 - Exam 2 First Name Last Name CSU# MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) An instance of describes system errors.

More information

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

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class. Name: Covers Chapters 1-3 50 mins CSCI 1301 Introduction to Programming Armstrong Atlantic State University Instructor: Dr. Y. Daniel Liang I pledge by honor that I will not discuss this exam with anyone

More information

Questions Answer Key Questions Answer Key Questions Answer Key

Questions Answer Key Questions Answer Key Questions Answer Key Benha University Term: 2 nd (2013/2014) Class: 2 nd Year Students Subject: Object Oriented Programming Faculty of Computers & Informatics Date: 26/4/2014 Time: 1 hours Exam: Mid-Term (B) Name:. Status:

More information

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

Chapter 8 Objects and Classes Dr. Essam Halim Date: Page 1 Assignment (1) Chapter 8 Objects and Classes Dr. Essam Halim Date: 18-3-2014 Page 1 Section 8.2 Defining Classes for Objects 1 represents an entity in the real world that can be distinctly identified.

More information

Date: Dr. Essam Halim

Date: Dr. Essam Halim Assignment (1) Date: 11-2-2013 Dr. Essam Halim Part 1: Chapter 2 Elementary Programming 1 Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use

More information

Chapter 1: Introduction to Computers, Programs, and Java

Chapter 1: Introduction to Computers, Programs, and Java Chapter 1: Introduction to Computers, Programs, and Java 1. Q: When you compile your program, you receive an error as follows: 2. 3. %javac Welcome.java 4. javac not found 5. 6. What is wrong? 7. A: Two

More information

CS 113 PRACTICE FINAL

CS 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 information

Instruction to students:

Instruction to students: Benha University 2 nd Term (2012) Final Exam Class: 2 nd Year Students Subject: Object Oriented Programming Faculty of Computers & Informatics Date: 20/5/2012 Time: 3 hours Examiner: Dr. Essam Halim Instruction

More information

CS170 Introduction to Computer Science Midterm 2

CS170 Introduction to Computer Science Midterm 2 CS170 Introduction to Computer Science Midterm 2 03/25/2009 Name: Solution You are to honor the Emory Honor Code. This is a closed book and closednotes exam, and you are not to use any other resource than

More information

WOSO Source Code (Java)

WOSO Source Code (Java) WOSO 2017 - Source Code (Java) Q 1 - Which of the following is false about String? A. String is immutable. B. String can be created using new operator. C. String is a primary data type. D. None of the

More information

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

1. 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 information

CS 113 MIDTERM EXAM 2 SPRING 2013

CS 113 MIDTERM EXAM 2 SPRING 2013 CS 113 MIDTERM EXAM 2 SPRING 2013 There are 18 questions on this test. The value of each question is: 1-15 multiple choice (3 pts) 17 coding problem (15 pts) 16, 18 coding problems (20 pts) You may get

More information

Computer Programming, I. Laboratory Manual. Final Exam Solution

Computer Programming, I. Laboratory Manual. Final Exam Solution Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Final Exam Solution

More information

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

Chapter 4 Loops. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. Chapter 4 Loops 1 Motivations Suppose that you need to print a string (e.g., "Welcome to Java!") a hundred times. It would be tedious to have to write the following statement a hundred times: So, how do

More information

Full download all chapters instantly please go to Solutions Manual, Test Bank site: testbanklive.com

Full download all chapters instantly please go to Solutions Manual, Test Bank site: testbanklive.com Introduction to Java Programming Comprehensive Version 10th Edition Liang Test Bank Full Download: http://testbanklive.com/download/introduction-to-java-programming-comprehensive-version-10th-edition-liang-tes

More information

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

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader Prelim 1 Solutions CS 2110, March 10, 2015, 5:30 PM 1 2 3 4 5 Total Question True False Short Answer Recursion Object Oriented Loop Invariants Max 20 15 20 25 20 100 Score Grader The exam is closed book

More information

CS-202 Introduction to Object Oriented Programming

CS-202 Introduction to Object Oriented Programming CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

First Name Last Name ID#

First Name Last Name ID# CIS 265 Sect 01 - V. Matos Exam-2 Spring-2015 First Name Last Name ID# (15 pts) MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) In the following

More information

b. Suppose you enter input from the console, when you run the program. What is the output?

b. Suppose you enter input from the console, when you run the program. What is the output? Part I. Show the printout of the following code: (write the printout next to each println statement if the println statement is executed in the program). a. Show the output of the following code: public

More information

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,

Chapter 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

Midterm Exam CS 251, Intermediate Programming March 12, 2014

Midterm 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 information

Inheritance and Polymorphism

Inheritance and Polymorphism Inheritance and Polymorphism Dr. M. G. Abbas Malik Assistant Professor Faculty of Computing and IT (North Jeddah Branch) King Abdulaziz University, Jeddah, KSA mgmalik@kau.edu.sa www.sanlp.org/malik/cpit305/ap.html

More information

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Islamic University of Gaza Faculty of Engineering Computer Engineering Department Student Mark Islamic University of Gaza Faculty of Engineering Computer Engineering Department Question # 1 / 18 Question # / 1 Total ( 0 ) Student Information ID Name Answer keys Sector A B C D E A B

More information

COMPUTER APPLICATIONS

COMPUTER APPLICATIONS COMPUTER APPLICATIONS (Theory) (Two hours) Answers to this Paper must be written on the paper provided separately. You will not be allowed to write during the first 15 minutes. This time is to be spent

More information

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution Ch 5 Arrays Multiple Choice Test 01. An array is a ** (A) data structure with one, or more, elements of the same type. (B) data structure with LIFO access. (C) data structure, which allows transfer between

More information

COS 126 General Computer Science Spring Written Exam 1

COS 126 General Computer Science Spring Written Exam 1 COS 126 General Computer Science Spring 2017 Written Exam 1 This exam has 9 questions (including question 0) worth a total of 70 points. You have 50 minutes. Write all answers inside the designated spaces.

More information

CS1150 Principles of Computer Science Objects and Classes

CS1150 Principles of Computer Science Objects and Classes CS1150 Principles of Computer Science Objects and Classes Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Object-Oriented Thinking Chapters 1-8

More information

Selected Questions from by Nageshwara Rao

Selected Questions from  by Nageshwara Rao Selected Questions from http://way2java.com by Nageshwara Rao Swaminathan J Amrita University swaminathanj@am.amrita.edu November 24, 2016 Swaminathan J (Amrita University) way2java.com (Nageshwara Rao)

More information

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution Ch 5 Arrays Multiple Choice 01. An array is a (A) (B) (C) (D) data structure with one, or more, elements of the same type. data structure with LIFO access. data structure, which allows transfer between

More information

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

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

More information

Special Member Functions

Special Member Functions CS 247: Software Engineering Principles Special Member Functions Readings: Eckel, Vol. 1 Ch. 11 References and the Copy Constructor Ch. 12 Operator Overloading ( operator= ) U Waterloo CS247 (Spring 2017)

More information

Special Member Functions. Compiler-Generated Destructor. Compiler-Generated Default Constructor. Special Member Functions

Special Member Functions. Compiler-Generated Destructor. Compiler-Generated Default Constructor. Special Member Functions Special Member Functions CS 247: Software Engineering Principles Special Member Functions Readings: Eckel, Vol. 1 Ch. 11 References and the Copy Constructor Ch. 12 Operator Overloading ( operator= ) C++

More information

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

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

Practice Midterm 1. Problem Points Score TOTAL 50

Practice Midterm 1. Problem Points Score TOTAL 50 CS 120 Software Design I Spring 2019 Practice Midterm 1 University of Wisconsin - La Crosse February 25 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages including the

More information

APCS Semester #1 Final Exam Practice Problems

APCS Semester #1 Final Exam Practice Problems Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Solutions to the 2005 exam

Solutions to the 2005 exam Solutions to the 2005 exam Question 1A [4] In this question, use only the following (algorithm format) Boolean expressions: comparison operators: , =,,, and Boolean logical operators: NOT, AND, OR

More information

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

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each Your Name: Your Pitt (mail NOT peoplesoft) ID: Part Question/s Points available Rubric Your Score A 1-6 6 1 pt each B 7-12 6 1 pt each C 13-16 4 1 pt each D 17-19 5 1 or 2 pts each E 20-23 5 1 or 2 pts

More information

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. CSC-220 Exam4 on Chapters 18 and 24. Closed Book, Closed Notes, Closed Internet MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What are the base

More information

CIS 110 Fall 2016 Introduction to Computer Programming 13 Oct 2016 Midterm Exam Answer Key

CIS 110 Fall 2016 Introduction to Computer Programming 13 Oct 2016 Midterm Exam Answer Key CIS 110 Fall 2016 Midterm 1 CIS 110 Fall 2016 Introduction to Computer Programming 13 Oct 2016 Midterm Exam Answer Key 1.) The Easy One (1 point total) Check cover sheet for name, recitation #, PennKey,

More information

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

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette COMP 250: Java Programming I Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette Variables and types [Downey Ch 2] Variable: temporary storage location in memory.

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance (part II) Polymorphism Version of January 21, 2013 Abstract These lecture notes

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance (part II) Polymorphism Version of January 21, 2013 Abstract These lecture notes

More information

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit. Name CS 110 Practice Final Exam originally from Winter, 2003 Instructions: closed books, closed notes, open minds, 3 hour time limit. There are 4 sections for a total of 49 points. Part I: Basic Concepts,

More information

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

CS 162, Lecture 25: Exam II Review. 30 May 2018 CS 162, Lecture 25: Exam II Review 30 May 2018 True or False Pointers to a base class may be assigned the address of a derived class object. In C++ polymorphism is very difficult to achieve unless you

More information

Method Overriding in Java

Method Overriding in Java Method Overriding in Java Whenever same method name is existing in both base class and derived class with same types of parameters or same order of parameters is known as method Overriding. Method must

More information

Constructor. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Constructor. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. Constructor Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design these classes so to avoid redundancy? The

More information

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini 24. Inheritance Java Fall 2009 Instructor: Dr. Masoud Yaghini Outline Superclasses and Subclasses Using the super Keyword Overriding Methods The Object Class References Superclasses and Subclasses Inheritance

More information

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber Chapter 10 Inheritance and Polymorphism Dr. Hikmat Jaber 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the

More information

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer STUDENT NAME: ID: The exam consists of five questions. There are a total of 10 points. You may use the back

More information

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini 22. Inheritance Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Superclasses and Subclasses Using the super Keyword Overriding Methods The Object Class References Inheritance Object-oriented programming

More information

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

Use the scantron sheet to enter the answer to questions (pages 1-6) Use the scantron sheet to enter the answer to questions 1-100 (pages 1-6) Part I. Mark A for True, B for false. (1 point each) 1. Abstraction allow us to specify an object regardless of how the object

More information

CS171:Introduction to Computer Science II

CS171:Introduction to Computer Science II CS171:Introduction to Computer Science II Department of Mathematics and Computer Science Li Xiong 9/7/2012 1 Announcement Introductory/Eclipse Lab, Friday, Sep 7, 2-3pm (today) Hw1 to be assigned Monday,

More information

Java Methods. Lecture 8 COP 3252 Summer May 23, 2017

Java Methods. Lecture 8 COP 3252 Summer May 23, 2017 Java Methods Lecture 8 COP 3252 Summer 2017 May 23, 2017 Java Methods In Java, the word method refers to the same kind of thing that the word function is used for in other languages. Specifically, a method

More information

Lecture Notes Chapter #9_b Inheritance & Polymorphism

Lecture Notes Chapter #9_b Inheritance & Polymorphism Lecture Notes Chapter #9_b Inheritance & Polymorphism Inheritance results from deriving new classes from existing classes Root Class all java classes are derived from the java.lang.object class GeometricObject1

More information

Object Oriented Modeling

Object Oriented Modeling Object Oriented Modeling Object oriented modeling is a method that models the characteristics of real or abstract objects from application domain using classes and objects. Objects Software objects are

More information

Name CIS 201 Midterm II: Chapters 1-8

Name CIS 201 Midterm II: Chapters 1-8 Name CIS 201 Midterm II: Chapters 1-8 December 15, 2010 Directions: This is a closed book, closed notes midterm. Place your answers in the space provided. The point value for each question is indicated.

More information

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

Name: Code: Lab: (circle one) 12MW 2MW 4MW 5:30MW 7:00MW C O M P 1 2 1 0 Fall 2005 Exam 2 11/03/2005 Page 1 of 9 Name: Code: Lab: (circle one) 12MW 2MW 4MW 5:30MW 7:00MW Multiple Choice 70 points (35 items @ 2 point each) Select the letter in front of the most

More information

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

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming s SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177 Programming Time allowed: THREE hours: Answer: ALL questions Items permitted: Items supplied: There is

More information

Review questions. Review questions, cont d. Class Definition. Methods. Class definition: methods. April 1,

Review questions. Review questions, cont d. Class Definition. Methods. Class definition: methods. April 1, April 1, 2003 1 Previous Lecture: Intro to OOP Class definition: instance variables & methods Today s Lecture: Instance methods Constructors Methods with input parameters Review questions Where do you

More information

CLASS DESIGN. Objectives MODULE 4

CLASS DESIGN. Objectives MODULE 4 MODULE 4 CLASS DESIGN Objectives > After completing this lesson, you should be able to do the following: Use access levels: private, protected, default, and public. Override methods Overload constructors

More information

Introduction to Programming (CS112): Sample

Introduction to Programming (CS112): Sample Introduction to Programming (CS112): Sample Name: Netid: ffl Write your answers directly on the examination paper, including any work that you wish to be considered for partial credit. Use the back side

More information

index.pdf January 21,

index.pdf January 21, index.pdf January 21, 2013 1 ITI 1121. Introduction to Computing II Circle Let s complete the implementation of the class Circle. Marcel Turcotte School of Electrical Engineering and Computer Science Version

More information

Lecture 5: Methods CS2301

Lecture 5: Methods CS2301 Lecture 5: Methods NADA ALZAHRANI CS2301 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Solution public static int sum(int i1, int i2) { int

More information

ECE Fall 20l2, Second Exam

ECE Fall 20l2, Second Exam ECE 30862 Fall 20l2, Second Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. LEAVE IT ON THE DESK. You have until 12:20 to take this exam. Your exam should have 16 pages total (including this cover

More information

Java Application Development

Java Application Development In order to learn which questions have been answered correctly: 1. Print these pages. 2. Answer the questions. 3. Send this assessment with the answers via: a. FAX to (212) 967-3498. Or b. Mail the answers

More information

NAME: c. (true or false) The median is always stored at the root of a binary search tree.

NAME: c. (true or false) The median is always stored at the root of a binary search tree. EE 322C Spring 2009 (Chase) Exam 2: READ THIS FIRST. Please use the back side of each page for scratch paper. For some of the questions you may need to think quite a bit before you write down an answer.

More information

CS260 Intro to Java & Android 03.Java Language Basics

CS260 Intro to Java & Android 03.Java Language Basics 03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance

More information

I. True/False: (2 points each)

I. True/False: (2 points each) CS 102 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2008 What is your name?: (2 points) There are three sections: I. True/False..............54 points; (27 questions, 2 points each)

More information

Object- Oriented Analysis, Design and Programming

Object- Oriented Analysis, Design and Programming Object- Oriented Analysis, Design and Programming Medialogy, Semester 4 Monday 19 April 2010 9.00 12.00 You have 3 hours to complete this examination. Neither written material nor electronic equipment

More information

1 Inheritance (8 minutes, 9 points)

1 Inheritance (8 minutes, 9 points) Name: Career Account ID: Recitation#: 1 CS180 Spring 2011 Exam 2, 6 April, 2011 Prof. Chris Clifton Turn Off Your Cell Phone. Use of any electronic device during the test is prohibited. Time will be tight.

More information

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003 1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 7, 2003 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do not need to

More information

Polymorphism and Interfaces. CGS 3416 Spring 2018

Polymorphism and Interfaces. CGS 3416 Spring 2018 Polymorphism and Interfaces CGS 3416 Spring 2018 Polymorphism and Dynamic Binding If a piece of code is designed to work with an object of type X, it will also work with an object of a class type that

More information

CMSC132 Summer 2018 Midterm 1

CMSC132 Summer 2018 Midterm 1 CMSC132 Summer 2018 Midterm 1 First Name (PRINT): Last Name (PRINT): Instructions This exam is a closed-book and closed-notes exam. Total point value is 100 points. The exam is a 80 minutes exam. Please

More information

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods. Inheritance Inheritance is the act of deriving a new class from an existing one. Inheritance allows us to extend the functionality of the object. The new class automatically contains some or all methods

More information

CMSC132 Summer 2018 Midterm 1. Solution

CMSC132 Summer 2018 Midterm 1. Solution CMSC132 Summer 2018 Midterm 1 Solution First Name (PRINT): Last Name (PRINT): Instructions This exam is a closed-book and closed-notes exam. Total point value is 100 points. The exam is a 80 minutes exam.

More information

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a Spring 2017 Name: TUID: Page Points Score 1 28 2 18 3 12 4 12 5 15 6 15 Total: 100 Instructions The exam is closed book, closed notes. You may not use a calculator, cell phone, etc. i Some API Reminders

More information

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Table of Contents 1 Reusing Classes... 2 1.1 Composition... 2 1.2 Inheritance... 4 1.2.1 Extending Classes... 5 1.2.2 Method Overriding... 7 1.2.3

More information

IST311. Advanced Issues in OOP: Inheritance and Polymorphism

IST311. Advanced Issues in OOP: Inheritance and Polymorphism IST311 Advanced Issues in OOP: Inheritance and Polymorphism IST311/602 Cleveland State University Prof. Victor Matos Adapted from: Introduction to Java Programming: Comprehensive Version, Eighth Edition

More information

COMP 401 Spring 2013 Midterm 1

COMP 401 Spring 2013 Midterm 1 COMP 401 Spring 2013 Midterm 1 I have not received nor given any unauthorized assistance in completing this exam. Signature: Name: PID: Please be sure to put your PID at the top of each page. This page

More information

public class SomeClass OtherClass SomeInterface { }

public class SomeClass OtherClass SomeInterface { } CMP 326 Final Fall 2015 Name: There is a blank page at the end of the exam if you need more room to answer a question. 1) (10 pts) Fill in the blanks to specify the missing keywords or definitions. public

More information

Chapter 5 Object-Oriented Programming

Chapter 5 Object-Oriented Programming Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares

More information

Control Structures in Java if-else and switch

Control Structures in Java if-else and switch Control Structures in Java if-else and switch Lecture 4 CGS 3416 Spring 2017 January 23, 2017 Lecture 4CGS 3416 Spring 2017 Selection January 23, 2017 1 / 26 Control Flow Control flow refers to the specification

More information

2. [20] Suppose we start declaring a Rectangle class as follows:

2. [20] Suppose we start declaring a Rectangle class as follows: 1. [8] Create declarations for each of the following. You do not need to provide any constructors or method definitions. (a) The instance variables of a class to hold information on a Minesweeper cell:

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

Outline for Today CSE 142. CSE142 Wi03 G-1. withdraw Method for BankAccount. Class Invariants

Outline for Today CSE 142. CSE142 Wi03 G-1. withdraw Method for BankAccount. Class Invariants CSE 142 Outline for Today Conditional statements if Boolean expressions Comparisons (=,!=, ==) Boolean operators (and, or, not - &&,,!) Class invariants Conditional Statements & Boolean Expressions

More information

CS 112 Programming 2. Lecture 06. Inheritance & Polymorphism (1) Chapter 11 Inheritance and Polymorphism

CS 112 Programming 2. Lecture 06. Inheritance & Polymorphism (1) Chapter 11 Inheritance and Polymorphism CS 112 Programming 2 Lecture 06 Inheritance & Polymorphism (1) Chapter 11 Inheritance and Polymorphism rights reserved. 2 Motivation Suppose you want to define classes to model circles, rectangles, and

More information

Lecture #6-7 Methods

Lecture #6-7 Methods Lecture #6-7 s 1. a. group of statements designed to perform a specific function b. may be reused many times i. in a particular program or ii. in multiple programs 2. Examples from the Java Library a.

More information

CS 307 Midterm 1 Fall 2007

CS 307 Midterm 1 Fall 2007 Points off 1 2 3 4 Total off Net Score CS 307 Midterm 1 Fall 2007 Your Name Your UTEID Circle yours TA s name: David Joseph Ola Instructions: 1. Please turn off your cell phones 2. There are 4 questions

More information

25. Generic Programming

25. Generic Programming 25. Generic Programming Java Fall 2009 Instructor: Dr. Masoud Yaghini Generic Programming Outline Polymorphism and Generic Programming Casting Objects and the instanceof Operator The protected Data and

More information

Lecture 7: Classes and Objects CS2301

Lecture 7: Classes and Objects CS2301 Lecture 7: Classes and Objects NADA ALZAHRANI CS2301 1 What is OOP? Object-oriented programming (OOP) involves programming using objects. An object represents an entity in the real world that can be distinctly

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract

More information