350 likes | 406 Views
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
E N D
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 • objects are instances of classes • objects and classes are the same thing • classes are programs while objects are variables • objects are the instance data of classes
To define a class that will represent a car, which of the following definitions is most appropriate? • private class car • public class car • public class Car • public class CAR • private class Car
Which of the following reserved words in Java is used to create an instance of a class? • class • public • public or private, either could be used • import • new
In order to preserve encapsulation of an object, we would do all of the following except for which one? • Make the instance data private • Define the methods in the class to access and manipulate the instance data • Make the methods of the class public • Make the class final • All of the above preserve encapsulation
If a method does not have a return statement, then • it will produce a syntax error when compiled • it must be a void method • it can not be called from outside the class that defined the method • it must be defined to be a public method • it must be an int, double, or String method
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? • m1 • m2 • m3 • m5 • main
A variable whose scope is restricted to the method where it was declared is known as a(n) • parameter • global variable • local variable • public instance data • private instance data
A class’ constructor usually defines • how an object is initialized • how an object is interfaced • the number of instance data in the class • the number of methods in the class • if the instance data are accessible outside of the object directly
Having multiple class methods of the same name where each method has a different number of or type of parameters is known as • encapsulation • information hiding • tokenizing • importing • method overloading
Instance data for a Java class • are limited to primitive types (e.g., int, double, char) • are limited to Strings • are limited to objects(e.g., Strings, classes defined by other programmers) • may be primitive types or objects, but objects must be defined to be private • may be primitive types or objects
An example of passing a message to a String where the message has a String parameter occurs in which of the following messages? • length • substring • equals • toUpperCase • none of the above, it is not possible to pass a String as a parameter in a message to a String
Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal? • foo(0, 0.1); • foo(0 / 1, 2 * 3); • foo(0); • foo( ); • foo(1 + 2, 3 * 0.1);
Consider a method defined with the header: public void doublefoo(double x). Which of the following method calls is legal? • doublefoo(0); • doublefoo(0.555); • doublefoo(0.1 + 0.2); • doublefoo(0.1, 0.2); • all of the above are legal except for d
What is a mutator method? • A method that modifies a value. • A method that provides read-only access to a value. • A method that has the same name, but different parameters, as another method. • A method that is called when an object is first created. • A method that does not return a value.
BioMed Tech Exam Review Chapter 5
For the first four questions, assume x and y are String variables with x = "Hello" and y = null.
The result of (x = = y) is • true • false • a syntax error • a run-time error • x being set to the value null
The result of x.length( ) + y.length( ) is • 0 • 5 • 6 • 10 • a thrown exception
If the operation y = "Hello"; is performed, then the result of (x = = y) is • true • false • x and y becoming aliases • x being set to the value null • a run-time error
If the operation y = x; is performed, then the result of (x = = y) is • true • false • x being set to the value null while y retains the value "Hello" • y being set to the value null while x retains the value "Hello" • x being set to y, which it is already since y = x; was already performed
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; } • x is now "Goodbye" and y is now "Hello" • x is now "Goodbye" and y is still "Goodbye", but (x != y) • x is still "Hello" and y is now "Hello", but (x != y) • x and y are now aliases • x and y remain unchanged
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. • equals (String) • toUpperCase (String) • sqrt (Math) • format (DecimalFormat) • paint (Applet)
Static methods cannot • reference instance data • reference non-static instance data • reference other objects • invoke other static methods • invoke non-static methods
An object that refers to part of itself within its own methods can use which of the following reserved words to denote this relationship? • inner • i • private • this • static
Which of the following interfaces would be used to implement a class that represents a group (or collection) of objects? • Iterator • Speaker • Comparable • MouseListener • KeyListener
In order to implement Comparable in a class, what method(s) must be defined in that class? • equals • compares • both lessThan and greaterThan • compareTo • both compares and equals
If s is a String, and s = “no”; is performed, then s • stores the String “no” • references the memory location where “no” is stored • stores the characters ‘n’, ‘o’ • stores an int value that represents the two characters • stores the character ‘n’ and a reference to the memory location where the next character, ‘o’ is stored
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? • The class must import another class which implements ActionListener • The class must define the method actionPerformed • The class must define the method ActionListener • The class must define an inner class called ActionListener • The class must define the method actionPerformed in an inner class named ActionListener
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? • ignore the exception • handle the exception where it arose using try and catch statements • propagate the exception to another method where it can be handled • throw the exception to a pre-defined Exception class to be handled • all of the above are ways that a Java program could handle an exception
An exception can produce a “call stack trace” which lists • the active methods in the order that they were invoked • the active methods in the opposite order that they were invoked • the values of all instance data of the object where the exception was raised • 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 • the name of the exception thrown
In order to have some code throw an exception, you would use which of the following reserved words? • throw • throws • try • Throwable • goto
JOptionPane is a class that provides GUI • dialog boxes • buttons • output fields • panels and frames • all of the above
A listener is an object that • implements any type of interface • is used to accept any form of input • is an inner class to a class that has abstract methods • waits for some action from the user • uses the InputStreamReader class