35
BioMed Tech Exam Review Chapter 4

BioMed Tech Exam Review

Embed Size (px)

DESCRIPTION

BioMed Tech Exam Review. Chapter 4. The behavior of an object is defined by the object’s instance data constructor visibility modifiers methods all of the above. The relationship between a class and an object is best described as classes are instances of objects - PowerPoint PPT Presentation

Citation preview

Page 1: BioMed Tech Exam Review

BioMed Tech Exam Review

Chapter 4

Page 2: BioMed Tech Exam Review

• The behavior of an object is defined by the object’s

A. instance data

B. constructor

C. visibility modifiers

D. methods

E. all of the above

Page 3: BioMed Tech Exam Review

• The relationship between a class and an object is best described as

A. classes are instances of objects

B. objects are instances of classes

C. objects and classes are the same thing

D. classes are programs while objects are variables

E. objects are the instance data of classes

Page 4: BioMed Tech Exam Review

• To define a class that will represent a car, which of the following definitions is most appropriate?

A. private class car

B. public class car

C. public class Car

D. public class CAR

E. private class Car

Page 5: BioMed Tech Exam Review

• Which of the following reserved words in Java is used to create an instance of a class?

A. class

B. public

C. public or private, either could be used

D. import

E. new

Page 6: BioMed Tech Exam Review

• In order to preserve encapsulation of an object, we would do all of the following except for which one?

A. Make the instance data private

B. Define the methods in the class to access and manipulate the instance data

C. Make the methods of the class public

D. Make the class final

E. All of the above preserve encapsulation

Page 7: BioMed Tech Exam Review

• If a method does not have a return statement, then

A. it will produce a syntax error when compiled

B. it must be a void method

C. it can not be called from outside the class that defined the method

D. it must be defined to be a public method

E. it must be an int, double, or String method

Page 8: BioMed Tech Exam Review

• Consider a sequence of method invocations as follows: main calls m1, m1 calls m2, m2 calls m3 and then m2 calls m4, m3 calls m5. If m4 has just terminated, what method will resume execution?

A. m1B. m2C. m3D. m5E. main

Page 9: BioMed Tech Exam Review

• A variable whose scope is restricted to the method where it was declared is known as a(n)

A. parameter

B. global variable

C. local variable

D. public instance data

E. private instance data

Page 10: BioMed Tech Exam Review

• A class’ constructor usually definesA. how an object is initialized

B. how an object is interfaced

C. the number of instance data in the class

D. the number of methods in the class

E. if the instance data are accessible outside of the object directly

Page 11: BioMed Tech Exam Review

• Having multiple class methods of the same name where each method has a different number of or type of parameters is known as

A. encapsulation

B. information hiding

C. tokenizing

D. importing

E. method overloading

Page 12: BioMed Tech Exam Review

• Instance data for a Java class A. are limited to primitive types (e.g., int, double, char)

B. are limited to Strings

C. are limited to objects(e.g., Strings, classes defined by other programmers)

D. may be primitive types or objects, but objects must be defined to be private

E. may be primitive types or objects

Page 13: BioMed Tech Exam Review

• An example of passing a message to a String where the message has a String parameter occurs in which of the following messages?

A. length

B. substring

C. equals

D. toUpperCase

E. none of the above, it is not possible to pass a String as a parameter in a message to a String

Page 14: BioMed Tech Exam Review

• Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal?

A. foo(0, 0.1);

B. foo(0 / 1, 2 * 3);

C. foo(0);

D. foo( );

E. foo(1 + 2, 3 * 0.1);

Page 15: BioMed Tech Exam Review

• Consider a method defined with the header: public void doublefoo(double x). Which of the following method calls is legal?

A. doublefoo(0);

B. doublefoo(0.555);

C. doublefoo(0.1 + 0.2);

D. doublefoo(0.1, 0.2);

E. all of the above are legal except for d

Page 16: BioMed Tech Exam Review

• What is a mutator method?A. A method that modifies a value.

B. A method that provides read-only access to a value.

C. A method that has the same name, but different parameters, as another method.

D. A method that is called when an object is first created.

E. A method that does not return a value.

Page 17: BioMed Tech Exam Review

BioMed Tech Exam Review

Chapter 5

Page 18: BioMed Tech Exam Review

• For the first four questions, assume x and y are String variables with x = "Hello" and y = null.

Page 19: BioMed Tech Exam Review

• The result of (x = = y) isA. true

B. false

C. a syntax error

D. a run-time error

E. x being set to the value null

Page 20: BioMed Tech Exam Review

• The result of x.length( ) + y.length( ) isA. 0

B. 5

C. 6

D. 10

E. a thrown exception

Page 21: BioMed Tech Exam Review

• If the operation y = "Hello"; is performed, then the result of (x = = y) is

A. true

B. false

C. x and y becoming aliases

D. x being set to the value null

E. a run-time error

Page 22: BioMed Tech Exam Review

• If the operation y = x; is performed, then the result of (x = = y) is

A. trueB. falseC. x being set to the value null while y retains

the value "Hello"D. y being set to the value null while x retains

the value "Hello"E. x being set to y, which it is already since y =

x; was already performed

Page 23: BioMed Tech Exam Review

Consider the following swap method. If String x = "Hello" and String y = "Goodbye", then swap(x, y); results in which of the following?

public void swap(String a, String b){ String temp; temp = a; a = b; b = temp;}

A. x is now "Goodbye" and y is now "Hello"B. x is now "Goodbye" and y is still "Goodbye", but (x != y)C. x is still "Hello" and y is now "Hello", but (x != y)D. x and y are now aliasesE. x and y remain unchanged

Page 24: BioMed Tech Exam Review

• Which of the following methods is a static method? The class in which the method is defined is given in parentheses following the method name.

A. equals (String)B. toUpperCase (String)C. sqrt (Math)D. format (DecimalFormat)E. paint (Applet)

Page 25: BioMed Tech Exam Review

• Static methods cannot A. reference instance data

B. reference non-static instance data

C. reference other objects

D. invoke other static methods

E. invoke non-static methods

Page 26: BioMed Tech Exam Review

• An object that refers to part of itself within its own methods can use which of the following reserved words to denote this relationship?

A. innerB. iC. privateD. thisE. static

Page 27: BioMed Tech Exam Review

• Which of the following interfaces would be used to implement a class that represents a group (or collection) of objects?

A. IteratorB. SpeakerC. ComparableD. MouseListenerE. KeyListener

Page 28: BioMed Tech Exam Review

• In order to implement Comparable in a class, what method(s) must be defined in that class?

A. equals

B. compares

C. both lessThan and greaterThan

D. compareTo

E. both compares and equals

Page 29: BioMed Tech Exam Review

• If s is a String, and s = “no”; is performed, then s

A. stores the String “no”B. references the memory location where “no” is

storedC. stores the characters ‘n’, ‘o’D. stores an int value that represents the two

charactersE. stores the character ‘n’ and a reference to the

memory location where the next character, ‘o’ is stored

Page 30: BioMed Tech Exam Review

• Assume that you are defining a class and you want to implement an ActionListener. You state addActionListener(this); in your class’ constructor. What does this mean?

A. The class must import another class which implements ActionListener

B. The class must define the method actionPerformedC. The class must define the method ActionListenerD. The class must define an inner class called

ActionListener E. The class must define the method actionPerformed in

an inner class named ActionListener

Page 31: BioMed Tech Exam Review

• A Java program can handle an exception in several different ways. Which of the following is not a way that a Java program could handle an exception?

A. ignore the exceptionB. handle the exception where it arose using try and catch

statementsC. propagate the exception to another method where it can

be handled D. throw the exception to a pre-defined Exception class to

be handledE. all of the above are ways that a Java program could

handle an exception

Page 32: BioMed Tech Exam Review

• An exception can produce a “call stack trace” which listsA. the active methods in the order that they were invokedB. the active methods in the opposite order that they were

invokedC. the values of all instance data of the object where the

exception was raisedD. the values of all instance data of the object where the

exception was raised and all local variables and parameters of the method where the exception was raised

E. the name of the exception thrown

Page 33: BioMed Tech Exam Review

• In order to have some code throw an exception, you would use which of the following reserved words?

A. throw

B. throws

C. try

D. Throwable

E. goto

Page 34: BioMed Tech Exam Review

• JOptionPane is a class that provides GUI

A. dialog boxes

B. buttons

C. output fields

D. panels and frames

E. all of the above

Page 35: BioMed Tech Exam Review

• A listener is an object that

A. implements any type of interface

B. is used to accept any form of input

C. is an inner class to a class that has abstract methods

D. waits for some action from the user

E. uses the InputStreamReader class