Object-Oriented Programming Exam Answer Key - 981 Verified Questions

Page 1


Object-Oriented Programming

Exam Answer Key

Course Introduction

Object-Oriented Programming is a foundational course that introduces students to the principles and techniques of developing software using the object-oriented paradigm. Emphasizing concepts such as classes, objects, inheritance, polymorphism, encapsulation, and abstraction, this course equips students with the skills to design and implement robust, modular, and reusable code. Through hands-on practice with an object-oriented programming language, students learn to structure complex programs, solve real-world problems, and develop applications that are easier to maintain and extend. This course provides a crucial understanding of modern software development and prepares students for advanced programming topics.

Recommended Textbook

Starting Out with Java From Control Structures through Data Structures 2nd Edition by Tony Gaddis

Available Study Resources on Quizplus

22 Chapters

981 Verified Questions

981 Flashcards

Source URL: https://quizplus.com/study-set/3640 Page 2

Chapter 1: Introduction to Computers and Java

Available Study Resources on Quizplus for this Chatper

42 Verified Questions

42 Flashcards

Source URL: https://quizplus.com/quiz/72352

Sample Questions

Q1) Syntax is:

A) Words that have a special meaning in the programming language

B) Rules that must be followed when writing a program

C) Punctuation

D) Symbols or words that perform operations

Answer: B

Q2) Colons are used to indicate the end of a Java statement.

A)True

B)False

Answer: False

Q3) This is a special language used to write computer programs.

A) Programming language

B) Operating system

C) Application

D) Pseudocode

Answer: A

Q4) Java source files end with the .class extension.

A)True

B)False

Answer: False

To view all questions and flashcards with answers, click on the resource link above. Page 3

Chapter 2: Java Fundamentals

Available Study Resources on Quizplus for this Chatper

53 Verified Questions

53 Flashcards

Source URL: https://quizplus.com/quiz/72353

Sample Questions

Q1) What will be displayed as a result of executing the following code? int x = 5,y = 20;

X += 32;

Y /= 4;

System.out.println("x = " + x + ",y = " + y);

A) x = 32,y = 4

B) x = 9,y = 52

C) x = 37,y = 5

D) x = 160,y = 80

Answer: C

Q2) Which of the following statements correctly creates a Scanner object for keyboard input?

A) Scanner kbd = new Scanner(System.keyboard);

B) Scanner keyboard(System.in);

C) Scanner keyboard = new Scanner(System.in);

D) Keyboard scanner = new Keyboard(System.in);

Answer: C

To view all questions and flashcards with answers, click on the resource link above.

Chapter 3: Decision Structures

Available Study Resources on Quizplus for this Chatper

52 Verified Questions

52 Flashcards

Source URL: https://quizplus.com/quiz/72354

Sample Questions

Q1) What is the value of x after the following code has been executed? int x = 75; Int y = 90; If ( x != y)

X += y;

A) 75

B) 90

C) 15

D) 165 Answer: D

Q2) Because the && operator performs short-circuit evaluation,your boolean expression will usually execute faster if the subexpression that is most likely false is on the left of the && operator.

A)True

B)False Answer: True

Q3) A local variable's scope always ends at the closing brace of the block of code in which it is declared.

A)True

B)False Answer: True

To view all questions and flashcards with answers, click on the resource link above. Page 5

Chapter 4: Loops and Files

Available Study Resources on Quizplus for this Chatper

48 Verified Questions

48 Flashcards

Source URL: https://quizplus.com/quiz/72355

Sample Questions

Q1) This is an item that separates other items.

A) Controller

B) Partition

C) Doorway

D) Delimiter

Q2) What will be printed after the following code is executed? for (int number = 5;number < = 15;number +=3)

System.out.print(number + ",");

A) 5,6,7,8,9,10,11,12,13,14,15,

B) 5,8,11,14,17,

C) 5,8,11,14,

D) This is an invalid for statement

Q3) In a for statement,the control variable can only be incremented.

A)True

B)False

Q4) This type of loop will always be executed at least once.

A) pre-test loop

B) post-test loop

C) sentinel loop

D) for loop

To view all questions and flashcards with answers, click on the resource link above. Page 6

Chapter 5: Methods

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/72356

Sample Questions

Q1) Only constants and variables may be passed as arguments to methods.

A)True

B)False

Q2) Local variables

A) are hidden from other methods

B) may have the same name as local variables in other methods

C) lose the values stored in them between calls to the method in which the variable is declared

D) All of the above

Q3) All @param tags in a method's documentation comment must

A) end with a */

B) appear after the general description of the method

C) appear before the method header

D) span several lines

Q4) The process of breaking a problem down into smaller pieces is called

A) functional decomposition

B) scientific method

C) top-down programming

D) whole-into-part

To view all questions and flashcards with answers, click on the resource link above. Page 7

Chapter 6: A First Look at Classes

Available Study Resources on Quizplus for this Chatper

49 Verified Questions

49 Flashcards

Source URL: https://quizplus.com/quiz/72357

Sample Questions

Q1) The public access specifier for a field indicates that the attribute may not be accessed by statements outside the class.

A)True

B)False

Q2) Which of the following statements will create a reference,str,to the String,"Hello,World"?

A) String str = "Hello,World";

B) string str = "Hello,World";

C) String str = new "Hello,World";

D) str = "Hello,World";

Q3) Look at the following statement. import java.util.Scanner; This is an example of

A) a wildcard import

B) an explicit import

C) unconditional import

D) conditional import

Q4) A constructor is a method that is automatically called when an object is created.

A)True

B)False

To view all questions and flashcards with answers, click on the resource link above. Page 8

Chapter 7: A First Look at Gui Applications

Available Study Resources on Quizplus for this Chatper

49 Verified Questions

49 Flashcards

Source URL: https://quizplus.com/quiz/72358

Sample Questions

Q1) Programs that operate in a GUI environment must be

A) event driven

B) in color

C) dialog boxes

D) layout managers

Q2) A GUI program automatically stops executing when the end of the main method is reached.

A)True

B)False

Q3) These types of components are coupled with their underlying peers.

A) Lightweight

B) Featherweight

C) Middleweight

D) Heavyweight

Q4) If button1 is a JButton object,which of the following statements will make its background blue?

A) button1.makeBackground(BLUE);

B) button1.setBackground(Color.BLUE);

C) button1.makeBackground(Color.BLUE);

D) button1.set.Background(BLUE);

Page 9

To view all questions and flashcards with answers, click on the resource link above.

Chapter 8: Arrays and the Arraylist Class

Available Study Resources on Quizplus for this Chatper

52 Verified Questions

52 Flashcards

Source URL: https://quizplus.com/quiz/72359

Sample Questions

Q1) What will be the value of x[1] after the following code is executed? int[] x = {22,33,44}; ArrayProcess(x);

Public static void arrayProcess(int[] a) { For(int k = 0;k < 3;k++) { A[k] = a[k] + 5; }

A) 27

B) 33

C) 38

D) 49

Q2) An ArrayList object automatically expands in size to accommodate the items stored in it.

A)True

B)False

To view all questions and flashcards with answers, click on the resource link above.

Chapter 9: A Second Look at Classes and Objects

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

Source URL: https://quizplus.com/quiz/72360

Sample Questions

Q1) Which of the following is not true about static methods?

A) It is not necessary for an instance of the class to be created to execute the method.

B) They are created by placing the key word static after the access specifier in the method header.

C) They are called from an instance of the class.

D) They are often used to create utility classes that perform operations on data,but have no need to collect and store data.

Q2) The this key word is the name of a reference variable that is available to all static methods.

A)True

B)False

Q3) If object1 and object2 are objects of the same class,to make object2 a copy of object1

A) assign object1 to object2,such as object2 = object1;

B) write a copy method that will make a field by field copy of object1 data members into object2 data members

C) use the Java copy method that is a part of the Java language

D) use the default constructor to create object2 with object1 data members

To view all questions and flashcards with answers, click on the resource link above.

11

Chapter 10: Text Processing and More About Wrapper

Classes

Available Study Resources on Quizplus for this Chatper

49 Verified Questions

49 Flashcards

Source URL: https://quizplus.com/quiz/72361

Sample Questions

Q1) What will be printed after the following code is executed? String str = "abc456"; Int m = 0; While ( m < 6 )

{ If (!Character.isLetter(str.charAt(m))) System.out.print( Character.toUpperCase(str.charAt(m))); M++;

}

A) 456

B) ABC456

C) ABC

D) abc456

Q2) You cannot assign a value to a wrapper class object.

A)True

B)False

Q3) StringBuilder objects are immutable.

A)True

B)False

Page 12

To view all questions and flashcards with answers, click on the resource link above.

Chapter 11: Inheritance

Available Study Resources on Quizplus for this Chatper

49 Verified Questions

49 Flashcards

Source URL: https://quizplus.com/quiz/72362

Sample Questions

Q1) In UML diagrams,inheritance is shown

A) With a line that has an open arrowhead at one end that points to the superclass

B) With a line that has an open arrowhead at one end that points to the subclass

C) With a line that has a closed arrowhead at one end that points to the superclass

D) With a line that has a closed arrowhead at one end that points to the subclass

Q2) Protected members are

A) not quite private

B) not quite public

C) Both A and B

D) Neither A or B

Q3) In the following statement,which is the interface? public class ClassA extends ClassB implements ClassC

A) ClassA

B) ClassB

C) ClassC

D) Cannot tell

To view all questions and flashcards with answers, click on the resource link above. Page 13

Chapter 12: Exceptions and Advanced File Io

Available Study Resources on Quizplus for this Chatper

46 Verified Questions

46 Flashcards

Source URL: https://quizplus.com/quiz/72363

Sample Questions

Q1) This is a section of code that gracefully responds to exceptions when they are thrown.

A) Thrown class

B) Default exception handler

C) Exception

D) Exception handler

Q2) If,within one try statement you want to have catch clauses that catch exceptions of the following types,in which order should they appear in your program? (1)Throwable (2)Exception

(3)RuntimeException

(4)NumberFormatException

A) 4,3,2,1

B) 2,3,1,4

C) 4,1,3,2

D) 3,1,2,4

Q3) A class must implement the Serializable interface in order for objects of the class to be serialized.

A)True

B)False

To view all questions and flashcards with answers, click on the resource link above.

Page 14

Chapter 13: Advanced Gui Applications

Available Study Resources on Quizplus for this Chatper

46 Verified Questions

46 Flashcards

Source URL: https://quizplus.com/quiz/72364

Sample Questions

Q1) The ImageIcon class constructor accepts

A) an integer that references the image.

B) a String argument which is the name of the image file.

C) a String argument which is the name of the image.

D) it does not accept any arguments.

Q2) If addressList exists and has values stored in it and addrList is an array with values stored in it,what will be the results when the following code is executed? addressList.setListData(addrList);

A) The values of addrList will be attached at the end of the current addressList.

B) The values in addressList will be replaced by the values in addrList.

C) The values of addrList will be inserted at the beginning of the current addressList.

D) addressList will be unchanged.

Q3) In the following code the setPreferredSize method sets the size of the text,"Have a good day".

label = new Jlabel("Have a good day",SwingConstants.CENTER);

label.setPreferredSize(new Dimension(400,200));

A)True

B)False

To view all questions and flashcards with answers, click on the resource link above.

Page 15

Chapter 14: Applets and More

Available Study Resources on Quizplus for this Chatper

39 Verified Questions

39 Flashcards

Source URL: https://quizplus.com/quiz/72365

Sample Questions

Q1) In the link produced by the following HTML,what word would you click to go to the linked location? Click here to learn more about < a href="http://www.applications.com" >applications.< /a >

A) Click

B) here

C) Click here to learn more about

D) applications

Q2) These are Java programs that are usually part of a Web site.

A) Applications

B) Applets

C) Classes

D) Web services

Q3) For all Swing components except JApplet and JFrame,you should override the paintComponent method instead of the paint method.

A)True

B)False

Q4) Whenever you need a component of any type to be painted,call the paint method.

A)True

B)False

To view all questions and flashcards with answers, click on the resource link above. Page 16

Chapter 15: Recursion

Available Study Resources on Quizplus for this Chatper

34 Verified Questions

34 Flashcards

Source URL: https://quizplus.com/quiz/72366

Sample Questions

Q1) A problem can be solved recursively if it can be broken down into successive smaller problems that are identical to the overall problem.

A)True

B)False

Q2) This type of method is a method that calls itself.

A) Looping

B) Circular

C) Recursive

D) Reoccurring

Q3) Like _________,a recursive method must have some way to control the number of times it repeats.

A) a loop

B) any method

C) a GUI method

D) a rumor

Q4) If Method A calls Method B which in turn calls Method A,it is called indirect recursion.

A)True

B)False

To view all questions and flashcards with answers, click on the resource link above.

Page 17

Chapter 16: Sorting, Searching, and Algorithm Analysis

Available Study Resources on Quizplus for this Chatper

46 Verified Questions

46 Flashcards

Source URL: https://quizplus.com/quiz/72367

Sample Questions

Q1) A search for an item X in a portion of a sorted array works by repeatedly selecting the middle item and comparing it to X.If X is not found there,the search method selects either the portion of the array to the left of the middle item,or the portion of the array to the right of the middle item,and continues the search.This method is called

A) sequential search

B) binary search

C) selection search

D) None of the above

Q2) The binary search algorithm

A) cannot be used to search an array that is not sorted

B) does twice as much work as sequential search on the average case

C) must be written using recursion

D) is slower than sequential search when the item being searched for is not in the array

Q3) For a computational problem,the input size

A) is the number of times the program requests input from the user

B) is the number of loop iterations required to read the input

C) is the amount of memory needed to store the input

D) None of the above

To view all questions and flashcards with answers, click on the resource link above. Page 18

Chapter 17: Generics

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/72368

Sample Questions

Q1) Consider a method of the form

Void printPoint(Point< Number > p){

//Code not shown

}

Where Point< T > is a generic type.When the method is called,the only objects that may be passed for the parameter p are

A) Point< Number > objects only

B) Point< T > objects,where T is the Number class,or is any subclass of Number

C) Point< T > objects,where T is the Number class,or is any superclass of Number

D) All of the above

Q2) The automatic conversion of a primitive type to the corresponding wrapper type when being passed as parameter to a generic class is called

A) type promotion

B) type wrapping

C) autoconversion

D) autoboxing

To view all questions and flashcards with answers, click on the resource link above.

19

Chapter 18: Collections

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/72369

Sample Questions

Q1) The code

List< String > myLs = new ArrayList< String >( );

Uses a List < String > interface variable to reference the concrete ArrayList< String > object.

The advantage of doing this is

A) the class of the collection object can later be changed to LinkedList,or even Vector,without needing to change anything else in the program

B) the class of the collection object can later be changed to LinkedList,Vector,TreeSet,or even HashSet,without needing to change anything else in the program

C) the program compiles faster

D) None of the above: the statement is a type error.

Q2) A TreeSet

A) is like a Set,only it is faster

B) is a Set that allows elements to be retrieved in the order added

C) is a Set that organizes its elements in a tree according to the inheritance hierarchy of the elements

D) is like a Set that allows elements to be retrieved according to their natural order,or according to an order specified by a Comparator

To view all questions and flashcards with answers, click on the resource link above.

20

Chapter 19: Array-Based Lists

Available Study Resources on Quizplus for this Chatper

20 Verified Questions

20 Flashcards

Source URL: https://quizplus.com/quiz/72370

Sample Questions

Q1) The size of an array-based list such as ArrayList

A) is the number of bytes of memory that the list can hold

B) is the number of elements that are currently stored in the list

C) is the length of its internal array

D) None of the above

Q2) A new element is added to an ArrayList object at index k.Assuming the list has size s and does not have to be resized,

A) the elements at current positions 0..k must be moved toward the beginning of the list

B) the elements at current positions k..s-1 must be moved toward the end of the array

C) the elements at current positions k..s must be moved toward the end of the array

D) the element at position k is overwritten

Q3) The position of an item within a list is called its

A) index

B) rank

C) level

D) number

To view all questions and flashcards with answers, click on the resource link above.

Chapter 20: Linked Lists

Available Study Resources on Quizplus for this Chatper

36 Verified Questions

36 Flashcards

Source URL: https://quizplus.com/quiz/72371

Sample Questions

Q1) The tail of a list

A) is an instance of a class that implements the ListTail interface

B) is what you get when take a list and remove its head

C) is a synchronized subclass of the LinkedList class

D) None of the above

Q2) A linked list class uses a Node class to represent nodes.A private recursive method Node add(int index,E element,Node list)takes a reference list (referring to the first in a chain of Node objects),adds a node containing the given element at the given index,and returns a reference to the first node of the resulting chain.Assume that index is nonnegative and is less than or equal to the size of list.Under these circumstances,the add method should handle its base case (index is 0)by

A) returning list

B) adding a node containing element to the front of list and returning a reference to the newly created node

C) adding a node containing element to the front of list and returning list

D) adding a node containing element to the end of list

To view all questions and flashcards with answers, click on the resource link above.

22

Chapter 21: Stacks and Queues

Available Study Resources on Quizplus for this Chatper

36 Verified Questions

36 Flashcards

Source URL: https://quizplus.com/quiz/72372

Sample Questions

Q1) A queue based on a linked list uses the following code Class Node{ String element; Node next;

Node (String el,Node n){

Element = el;

Next = n; } }

Node front,rear;

What is the right code for a constructor for such a linked list class?

A) element = el;next = n;

B) front = rear;

C) front = null;rear = null;

D) front = element;rear = front;

Q2) The operation for adding an item to a queue is called

A) requeue

B) enqueue

C) dequeue

D) proqueue

To view all questions and flashcards with answers, click on the resource link above.

Page 23

Chapter 22: Binary Trees, Avl Trees, and Priority Queues

Available Study Resources on Quizplus for this Chatper

45 Verified Questions

45 Flashcards

Source URL: https://quizplus.com/quiz/72373

Sample Questions

Q1) The predecessor of a node in a binary tree is called its A) progenitor

B) ancestor

C) parent

D) precursor

Q2) The heap sort method has a worst case complexity function that is in

A) O(log n)

B) O(n.

C) O(n2.

D) O(n log n.

Q3) Consider the operation of deleting the root of a binary search tree.If the root is a leaf,then

A) the method doing the deletion should throw an exception

B) the root should be replaced with a dummy place-holder node

C) the reference to the root of the tree should be set to null

D) the element stored in the root node should be replaced with null,or with 0.

To view all questions and flashcards with answers, click on the resource link above.

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.