CS26 Exam 1. Multiple Choice Identify the choice that best completes the statement or answers the question.

Similar documents
Fundamentals of Java Programming

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

CS 111 Classes I 1. Software Organization View to this point:

CS506 Web Design and Development Solved Online Quiz No. 01

Part I. Multiple Choice Questions (2 points each):

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism

I. INTRODUCTION. International Journal of Computer Science Trends and Technology (IJCST) Volume 3 Issue 2, Mar-Apr 2015

PLV Goldstein 315, Tuesdays and Thursdays, 6:00PM-7:50PM. Tuesdays and Thursdays, 4:00PM-5:30PM and 7:50PM 9:30PM at PLV G320

Java Interview Questions and Answers

History OOP languages Year Language 1967 Simula Smalltalk

Exception Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1

Java Programming Language

Chapter 13 - Inheritance

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

Java Application Developer Certificate Program Competencies

The Interface Concept

Programming Languages Featherweight Java David Walker

Chapter 1 Fundamentals of Java Programming

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

What are exceptions? Bad things happen occasionally

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

Programmation 2. Introduction à la programmation Java

Glossary of Object Oriented Terms

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Compile-time type versus run-time type. Consider the parameter to this function:

Advanced Data Structures

AP Computer Science Java Subset

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Description of Class Mutation Mutation Operators for Java

Specialized Programme on Web Application Development using Open Source Tools

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

D06 PROGRAMMING with JAVA

Java CPD (I) Frans Coenen Department of Computer Science

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Object Oriented Software Design

Object-Oriented Programming: Polymorphism

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

11 November

JAVA - EXCEPTIONS. An exception can occur for many different reasons, below given are some scenarios where exception occurs.

Specialized Programme on Web Application Development using Open Source Tools

Lecture J - Exceptions

Crash Course in Java

TECHNOLOGY Computer Programming II Grade: 9-12 Standard 2: Technology and Society Interaction

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

LAB4 Making Classes and Objects

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

Java (12 Weeks) Introduction to Java Programming Language

java Features Version April 19, 2013 by Thorsten Kracht

JAVA INTERVIEW QUESTIONS

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Computing Concepts with Java Essentials

public static void main(string args[]) { System.out.println( "f(0)=" + f(0));

An Introduction To UML Class Diagrams Classes

Abstract Class & Java Interface

Dennis Olsson. Tuesday 31 July

Classes Dennis Olsson

Object-Oriented Programming Lecture 2: Classes and Objects

AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities

VB.NET - CLASSES & OBJECTS

D06 PROGRAMMING with JAVA

CS193j, Stanford Handout #10 OOP 3

Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

C++ INTERVIEW QUESTIONS

Habanero Extreme Scale Software Research Project

Laboratory Assignments of OBJECT ORIENTED METHODOLOGY & PROGRAMMING (USING C++) [IT 553]

Object Oriented Programming and the Objective-C Programming Language 1.0. (Retired Document)

Block IQ. Marko Boon Jacques Resing

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Inheritance, overloading and overriding

Polymorphism. Why use polymorphism Upcast revisited (and downcast) Static and dynamic type Dynamic binding. Polymorphism.

Syllabus for CS 134 Java Programming

Contents. 9-1 Copyright (c) N. Afshartous

Introduction to Java Applets (Deitel chapter 3)

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

Java SE 8 Programming

ICOM 4015: Advanced Programming

Java Programming Fundamentals

RMI Client Application Programming Interface

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Java from a C perspective. Plan

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science

CEC225 COURSE COMPACT

Introduction: Abstract Data Types and Java Review

Copyright. Restricted Rights Legend. Trademarks or Service Marks. Copyright 2003 BEA Systems, Inc. All Rights Reserved.

What is Java? Applications and Applets: Result of Sun s efforts to remedy bad software engineering practices

Construction of classes with classes

iphone SDK Enrolled students will be invited to developer program Login to Program Portal Request a Certificate Download and install the SDK

JAVA - INHERITANCE. extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword.

Basic Object-Oriented Programming in Java

Génie Logiciel et Gestion de Projets. Object-Oriented Programming An introduction to Java

Chapter 2 Introduction to Java programming

The Class Blueprint A Visualization of the Internal Structure of Classes

3 Improving the Crab more sophisticated programming

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Part 3: GridWorld Classes and Interfaces

Transcription:

CS26 Exam 1 Multiple Choice Identify the choice that best completes the statement or answers the question. 1. Inheritance is the process by which a new class known as a - is created from another class, called the. a. base class, derived class c. inherited class, base class b. derived class, base class d. base class, inherited class 2. Inheritance promotes code. a. reinvention c. repeats b. reuse d. all of the above 3. The keyword extends indicates: a. encapsulation c. inheritance b. polymorphism d. none of the above 4. What does a derived class automatically inherit from the base class? a. instance variables c. public methods b. static variables d. all of the above 5. If the final modifier is added to the definition of a method, this means: a. The method may be redefined in the derived class. b. The method may be redefined in the sub class. c. The method may not be redefined in the derived class. d. None of the above. 6. The special syntax for invoking a constructor of the base class is: a. super() c. parent() b. base() d. child() 7. An object of a derived class has the type of the derived class, and it also has the type of the base class, and more generally, has the type of every one of its classes. a. descendant c. ancestor b. child d. sub 8. In using the keyword this() in place of super(), the invocation of this() must be the action taken by the constructor. a. first c. it does not matter b. last d. none of the above 9. The class is an ancestor class of all Java classes. a. String c. Math b. Object d. JFrame 10. The Object class contains the method: a. getclass() c. equals() b. tostring() d. all of the above 11. The equals method for a class should have as the type of its one parameter. a. String c. Integer

b. Object d. Double 12. The principals of object oriented programming include: a. encapsulation c. polymorphism b. inheritance d. all of the above 13. binding refers to the method definition being associated with the method invocation when the code is compiled. a. Dynamic c. Early b. Late d. None of the above 14. refers to the ability to associate many meanings to one method name by means of the late binding mechanism. a. Inheritance c. Polymorphism b. Encapsulation d. None of the above 15. A method marked as final means the compiler uses binding. a. dynamic c. late b. early d. none of the above 16. Java does not use late binding for methods marked as: a. final c. private b. static d. all of the above 17. Assigning an object of a derived class to a variable of a base class is called: a. static binding c. upcasting b. dynamic binding d. downcasting 18. Assigning an object of an ancestor class to a descendent class is called: a. static binding c. upcasting b. dynamic binding d. downcasting 19. You cannot create an object using a/an: a. superclass constructor c. ancestor class constructor b. subclass constructor d. abstract class constructor 20. An abstract method cannot be modified by: a. public c. private b. protected d. none of the above 21. A class that has at least one abstract method is called an: a. concrete class c. abstract class b. encapsulated class d. private class 22. A class with no abstract methods is called a a. concrete class c. abstract class b. encapsulated class d. private class 23. try blocks contain code that could possibly: a. handle an exception c. catch an exception b. throw an exception d. display an exception 24. The Exception class belongs to the package: a. java.io c. java.lang

b. java.util d. java.except 25. The execution of a throw statement is referred to as: a. catching a block c. handling an exception b. trying a block d. throwing an exception 26. The catch block has parameters. a. zero c. two b. one d. three 27. A block should immediately follow a try block. a. try c. fail b. catch d. final 28. If a method does not catch an exception, then it must at least warn programmers that any invocation of the method might possibly throw an exception. This warning is called a/an: a. Exception handler c. try block b. throws clause d. catch block 29. Which circumstance is an exception to the catch or declare rule? a. Exceptions that result from errors of some sort. b. Exceptions that are descendents of the class RuntimeException. c. Both A and B d. None of the above 30. Exceptions that are subject to the catch or declare rule are called: a. Checked exceptions c. Fatal exceptions b. Unchecked exceptions d. All of the above 31. A runtime exception is a/an: a. checked exception c. offending exception b. unchecked exception d. none of the above 32. All exceptions are descendants of the class: a. Throwable c. Tryable b. Catchable d. Blockable 33. Exception handling is an example of a programming methodology known as: a. structured programming c. goto programming b. object oriented programming d. event-driven programming 34. A block executes regardless of whether an exception occurs. a. final c. catch b. finally d. none of the above 35. ArrayIndexOutOfBoundsException is a descendent of the class RuntimeException. This means: a. the exception must be caught b. a finally block must be included c. the exception does not have to be explicitly caught d. none of the above 36. An exception is caught in a block.

a. try c. finally b. catch d. all of the above True/False Indicate whether the statement is true or false. 37. A derived class contains only public instance variables and public methods from the base class. 38. A derived class is a class defined by adding instance variables and methods to an existing class. 39. Overriding is when a derived class redefines a method from the base class. 40. You may substitute the keyword this() for super() to call a constructor of the derived class. 41. An instance variable (or method) that is private in a base class is accessible by name in the definition of a method in any other class. 42. Polymorphism refers to the ability to associate many meanings to one method through dynamic binding. 43. Java allows an instance of an abstract class to be instantiated. 44. Late binding refers to the method definition being associated with the method invocation when the method is invoked at run time. 45. The final modifier is included before the definition of the method, then the method can be redefined in a derived class. 46. The type of the variable naming an object determines which method names can be used in an invocation with that calling object. 47. An abstract class is a class that has some methods without complete definitions. 48. An abstract method serves as a placeholder for a method that must be defined in all derived classes. 49. The throw operator causes a change in the flow of control. 50. When an exception is thrown, the code in the surrounding try block continues executing and then the catch block begins execution. 51. The two most important things about an exception object are its type and the message that it carries in an instance variable of type String. 52. A program can catch multiple exceptions. 53. The compiler does not complain when the catch or declare rule is ignored. 54. You can not place a try block and its following catch blocks inside a larger try block or inside a larger catch block. 55. The finally block contains code to be executed whether or not an exception is thrown in a try block. Problem

56. [20 pts] Java graphics considers all drawable objects as living inside a bounding rectangle. The rectangle has a position defined by the upper-left corner (x, y). The rectangle has a size defined by the width and height (w, h) of the rectangle. All values are measured in integer pixel counts. Consider the abstract class Shape that contains the data fields: x, y, w, and h. It also contains the abstract method: double area(). There are two descendent classes from Shape, namely Rect and Oval. Write minimal classes for Shape, Rect, and Oval. Include the above mentioned data fields, constructors (complete only), and the method area(). No need for any other methods. The formula for the area of a rectangle is the product of its width and height. The formula for the area of an oval (or ellipse) is π (pi) times the product of the radii along the major and minor axes, from the center of the oval to the edge of the oval (which happens to interesect with the outline of the bounding rectangle).

CS26 Exam 1 Answer Section MULTIPLE CHOICE 1. ANS: B PTS: 1 2. ANS: B PTS: 1 3. ANS: C PTS: 1 4. ANS: D PTS: 1 5. ANS: C PTS: 1 6. ANS: A PTS: 1 7. ANS: C PTS: 1 8. ANS: A PTS: 1 9. ANS: B PTS: 1 10. ANS: D PTS: 1 11. ANS: B PTS: 1 12. ANS: D PTS: 1 13. ANS: C PTS: 1 14. ANS: C PTS: 1 15. ANS: B PTS: 1 16. ANS: D PTS: 1 17. ANS: C PTS: 1 18. ANS: D PTS: 1 19. ANS: D PTS: 1 20. ANS: C PTS: 1 21. ANS: C PTS: 1 22. ANS: A PTS: 1 23. ANS: B PTS: 1 24. ANS: C PTS: 1 25. ANS: D PTS: 1 26. ANS: B PTS: 1 27. ANS: B PTS: 1 28. ANS: B PTS: 1 29. ANS: C PTS: 1 30. ANS: A PTS: 1 31. ANS: B PTS: 1 32. ANS: A PTS: 1 33. ANS: D PTS: 1 34. ANS: B PTS: 1 35. ANS: C PTS: 1 36. ANS: B PTS: 1 TRUE/FALSE 37. ANS: F PTS: 1 38. ANS: T PTS: 1

39. ANS: T PTS: 1 40. ANS: T PTS: 1 41. ANS: F PTS: 1 42. ANS: T PTS: 1 43. ANS: F PTS: 1 44. ANS: T PTS: 1 45. ANS: F PTS: 1 46. ANS: T PTS: 1 47. ANS: T PTS: 1 48. ANS: T PTS: 1 49. ANS: T PTS: 1 50. ANS: F PTS: 1 51. ANS: T PTS: 1 52. ANS: T PTS: 1 53. ANS: F PTS: 1 54. ANS: F PTS: 1 55. ANS: T PTS: 1 PROBLEM 56. ANS: public abstract class Shape protected int x, y; protected int w, h; // 2 pts // 2 pts protected Shape(int x, int y, int w, int h) // 3 pts this.x = x; this.y = y; this.w = w; this.h = h; public abstract double area(); // 3 pts public class Rect extends Shape // 2 pts public Rect(int x, int y, int w, int h) // 2 pts super(x, y, w, h); public double area() return this.w * this.h; // 2 pts

public class Oval extends Shape // 1 pts public Oval(int x, int y, int w, int h) super(x, y, w, h); public double area() // 3 pts return (Math.PI / 4.0) * (this.w * this.h); PTS: 20