CS 1331 Fall 2016 Exam 2

Similar documents
CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

CS 1331 Exam 1 ANSWER KEY

CS 1331 Fall 2016 Exam 3 Part 1 ANSWER KEY

Exam Percentage: / 55 = %

CS 1322 Test 2 - Version 1 Tuesday June 24 th

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

CS 1331 Exam 3 Practice

JAVA MOCK TEST JAVA MOCK TEST II

CS 1316 Exam 1 Summer 2009

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

Java Object Oriented Design. CSC207 Fall 2014

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

Inheritance (Outsource: )

CS 2316 Exam 3. Practice. Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

CISC 3115 Modern Programming Techniques Spring 2018 Section TY3 Exam 2 Solutions

CS Exam 2 - Spring 2010

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

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

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

What is Inheritance?

CS111: PROGRAMMING LANGUAGE II

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Inheritance and Polymorphism

Last Name: Circle One: OCW Non-OCW

First IS-A Relationship: Inheritance

Polymorphism. Arizona State University 1

CS 1331 Exam 3 Practice ANSWER KEY

Distributed Systems Recitation 1. Tamim Jabban

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

Assignment 1 due Monday at 11:59pm

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

Data Structures. Data structures. Data structures. What is a data structure? Simple answer: a collection of data equipped with some operations.

Final Exam CS 251, Intermediate Programming December 10, 2014

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

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

CSE 142, Spring 2009, Sample Final Exam #2. Good luck!

CS 113 PRACTICE FINAL

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Lecture 02, Fall 2018 Friday September 7

Introduction to Programming Using Java (98-388)

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

C# Programming for Developers Course Labs Contents

CSE 131S Introduction to Computer Science Summer SON Exam I

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Create a Java project named week10

CS-202 Introduction to Object Oriented Programming

CMSC 341. Nilanjan Banerjee

Lecture 2: Java & Javadoc

CS 101 Spring 2007 Midterm 2 Name: ID:

Assignment3 CS206 Intro to Data Structures Fall Part 1 (50 pts) due: October 13, :59pm Part 2 (150 pts) due: October 20, :59pm

Questions Answer Key Questions Answer Key Questions Answer Key

Distributed Systems Recitation 1. Tamim Jabban

CS 2102 Exam 2 D-Term 2013

More About Objects. Zheng-Liang Lu Java Programming 255 / 282

Abstract Classes and Interfaces

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

Chapter 14 Abstract Classes and Interfaces

Inheritance (Part 5) Odds and ends

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

CS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4

CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016

type conversion polymorphism (intro only) Class class

More Relationships Between Classes

COMP 250. Lecture 32. polymorphism. Nov. 25, 2016

Week 5-1: ADT Design

CS 113 MIDTERM EXAM 2 SPRING 2013

Final Exam Practice Questions

CS 251 Intermediate Programming Methods and Classes

Arrays Classes & Methods, Inheritance

Chapter 5 Object-Oriented Programming

Midterm Exam CS 251, Intermediate Programming March 6, 2015

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

OOP in Java Review. CS356 Object-Oriented Design and Programming October 1, 2014

Abstract class & Interface

CSE1720. General Info Continuation of Chapter 9 Read Chapter 10 for next week. Second level Third level Fourth level Fifth level

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

Midterm Exam CS 251, Intermediate Programming March 12, 2014

Chapter 4 Defining Classes I

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

CS1004: Intro to CS in Java, Spring 2005

CIT Special final examination

CO Java SE 8: Fundamentals

Class Hierarchy and Interfaces. David Greenstein Monta Vista High School

Chapter 6 Introduction to Defining Classes

AP CS Unit 6: Inheritance Notes

CS 1301 Exam 1 Fall 2010

Java Fundamentals (II)

Written Test 2. CSE Section M, Winter p. 1 of 8. Family Name: Given Name(s): Student Number:

I. True/False: (2 points each)

CS 305j Midterm 2 Fall 2006

Topic 7: Inheritance. Reading: JBD Sections CMPS 12A Winter 2009 UCSC

Introduction to Inheritance

Data Structures Lecture 2

Inheritance, cont. Notes Chapter 6 and AJ Chapters 7 and 8

Object- Oriented Analysis, Design and Programming

Prelim 1. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer. OO Recursion Loop invariants Max Score Grader

Introduction to Classes and Objects. David Greenstein Monta Vista High School

Programming II (CS300)

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

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

Transcription:

CS 1331 Fall 2016 Exam 2 Fall 2016 Name (print clearly): GT account (gpburdell1, msmith3, etc): Section (e.g., B1): Signature: Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score. Signing signifies you are aware of and in accordance with the Academic Honor Code of Georgia Tech and that you will not discuss this exam with other students. Calculators and cell phones are NOT allowed. This is an object-oriented programming test. Java is the required language. Java is case-sensitive. DO NOT WRITE IN ALL CAPS. A Java program in all caps will not compile. Good variable names and style are required. Comments are not required. Question Points per Page Points Lost Points Earned Graded By Page 1 16 - = Page 2 6 - = Page 3 10 - = Page 4 14 - = Page 5 3 - = Page 6 14 - = TOTAL 78 - =

1. Multiple Choice Circle the letter of the correct choice. [2] (a) A Polymorphic object is known as at runtime A. Static B. Dynamic C. Transformed D. Poly [2] (b) The reserved word used for the lower class in the inheritance hierarchy is A. Inherits B. Extends C. Receives D. Implements [2] (c) The type of relationship that exists in inheritance is A. Has-a B. Can-be C. Will-be D. Is-a [2] (d) To create a polymorphic Television object that is an Electronic object at compile time use: A. Television tele = new Electronic() B. Electronic el = new Television() C. Television tele = new Television() D. Electronic el = new Electronic() [2] (e) True or False: Java supports multiple inheritance. A. True B. False C. Only if both inherited classes are abstract classes. [2] (f) When a class hides information from its users it is taking part in a process known as A. Abstraction B. Instantiation C. Encapsulation D. Inheritance E. Polymorphism [2] (g) Given the following enum class and a variable myta that has been declared to be of that class: public enum TA { MARC, FARHAN, HARSH, CHRIS, ANIRUDDHA, TAYLOR; What should be placed in a conditional statement to correctly check if myta is Taylor? A. myta == TAYLOR B. new TA(TAYLOR) C. myta == TA.TAYLOR D. myta == new TA( TAYLOR ) E. myta.equals( TAYLOR ) [2] (h) Car c = new Car(); is an example of what? Choose the best answer A. Abstraction B. Instantiation C. Encapsulation D. Inheritance E. Polymorphism Page 1 of 8 Points available: 16 - points lost: = points earned:. Graded by:

[2] (i) Assume the following code has been executed: int[] nums = {3, 1, 4, 1, 5, 9; int[] numscopy = nums; int[] othernums; nums[3] = 7; numscopy[3] = 9; What is the value of nums[3]? A. 7 B. 4 C. 9 D. 1 [2] (j) Now assume that this line of code has been run (after the above code has run): nums[4] = numscopy[4] * 2; What is the value of numscopy[4]? A. 5 B. 10 C. 18 D. 9 [2] (k) Next, the following line of code is run: othernums = new int[6]; for(int i = 0; i < nums.length; i++) { othernums[i] = nums[i]; othernums[5] = 6; nums[5] = 2; Which of the following are true? A. othernums[5] == 2 && numscopy[5] == 6 B. othernums[5] == 6 && numscopy[5] == 9 C. othernums[5] == 2 && numscopy[5] == 2 D. othernums[5] == 6 && numscopy[5] == 2 Page 2 of 8 Points available: 6 - points lost: = points earned:. Graded by:

2. Consider the following classes. You can assume each class has been properly created and all required methods have been fully implemented: public interface Fightable * boolean canfight() public abstract class Superhero implements Fightable * public abstract void fightcrime() public class TeenTitan extends Superhero * public void describecostume() public class Raven extends TeenTitan * public void describecostume() public class Superman extends Superhero * public String getsecretidentity() * public String describecostume() For each of the below statements, write whether it will produce a compile time exception, a runtime exception, or no exception. If it produces an exception describe the problem in one sentence. If it produces no exception, write which class s method will get executed. For example: TeenTitan t = new TeenTitan(); t.describecostume(); "No exception. TeenTitan s describecostume" [2] (a) TeenTitan t1 = new Raven(); t1.describecostume(); [2] (b) Superhero s1 = new Raven(); s1.describecostume(); [2] (c) Superhero s2 = new Superhero(); s1.fightcrime(); [2] (d) Superhero s3 = new Raven(); ((Raven) s3).fightcrime(); [2] (e) Raven r1 = new Raven(); r1.fightcrime(); Page 3 of 8 Points available: 10 - points lost: = points earned:. Graded by:

[2] (f) Superman sm1 = new SuperHero(); sm1.fightcrime(); [2] (g) Superhero sm2 = new Superman(); sm2.fightcrime(); [2] (h) Raven r2 = new Superman(); r2.getsecretidentity(); [2] (i) Raven r3 = new Raven(); r3.getsecretidentity(); [2] (j) Superhero s4 = new TeenTitan(); s4.fightcrime(); [2] (k) Superhero s5 = new Fightable(); System.out.println(s5.canFight()); [2] (l) Superhero s6 = new Superman(); System.out.println(s6.canFight()); Page 4 of 8 Points available: 14 - points lost: = points earned:. Graded by:

3. Short Answer Answer the questions in the allotted space. Given the following classes: public class Dog { protected String sound; public Dog(String sound) { this.sound = sound; public void setbark(string sound) { this.sound = sound; public class Chihuahua extends Dog { public Chihuahua(String sound) { super(sound); public String bark() { return sound; public String tostring() { return sound; public class Driver { public static void main(string[] args) { Dog diego = new Chihuahua("woof woof"); Chihuahua pedro = new Chihuahua("arf"); System.out.println(diego.bark()); pedro = (Chihuahua)diego; System.out.println(pedro.bark()); diego.setbark("aroooof"); System.out.println(pedro.bark()); [3] (a) In the Driver class, locate the line of code that does not compile and fix it below. (Write the original line and what the line should have been. Page 5 of 8 Points available: 3 - points lost: = points earned:. Graded by:

[3] (b) Now assuming the change in part a has been made and the code compiles, write the output of the Driver class below. [3] (c) Now replace all the code in the Driver s main method with the following four lines of code. What would the output of this code be? Dog[] dogs = {new Chihuahua("la"), new Dog("woof"), new Dog("arf"); for (Dog d:dogs) { System.out.println(d); [4] (d) Suppose we make the Dog class abstract (public abstract class Dog) and a method (public abstract void walk();) is added to it. Make any necessary changes to the Chihuahua class in the space given below. [4] (e) Suppose we change the class header to indicate that the Chihuahua class implements Comparable. What would we need to add to the Chihuahua class? You do not need to write any code for this question, just explain what would have to be added. Page 6 of 8 Points available: 14 - points lost: = points earned:. Graded by:

[15] 4. Write the code. You are given an abstract circus performer class. Your task is to write a concrete subclass of CircusPerformer. You may name it whatever you like. However, your subclass must add the following functionality: * Have a private instance variable numberofteeth of type int. * Have a constructor that takes in a String name and an int numberofteeth that appropriately sets all instance data. * Provide a new implementation of the tostring method, that returns a String in the format, name has numberofteeth teeth. Write your code on the following page. Remember that there will be additional requirement(s) since the CircusPerformer class is abstract! public abstract class CircusPerformer { private String name; public CircusPerformer(String name) { this.name = name; public void sayhi() { System.out.println("Hi! My name is " + name); @Override public String tostring() { return this.name; public abstract void perform(); Page 7 of 8 Points available: 15 - points lost: = points earned:. Graded by:

Write your code here. Page 8 of 8 Points available: 0 - points lost: = points earned:. Graded by: