One or more objects may be created from (an)
a. field
b. class
c. method
d. instance
Class objects normally have _______ that perform useful operation on their data, but primitive variables do not
a. fields
b. instances
c. methods
d. relationships
In the cookie cutter metaphor, think of the _____ as a cookie cutter and _____ as the cookies
a. object; classes
b. class; objects
c. class; fields
d. attribute; methods
A UML diagram does not contain
a. the class names
b. the method names
c. the field names
d. object names
Data hiding, which means that critical data stored inside the object is protected from code outside the object is accomplished in java by
a. using the public access specifier on the class methods
b. using the private access specifier on the class methods
c. using the private access specifier on the class definition
d. using the private access specifier on the class fields
for the following code which statement is not true?
Public class Sphere
{
private double radius;
public double x;
private double y;
private double z;
}
a. x is available to code that is written outside the class circle
b. radius is not available to code written outside the radius circle
c. radius x,y,z are called members of the circle class
d. z is available to code that is written outside the circle class
You should not define a class field that is dependent upon the values of other class fields...
a. in order to avoid having stale data
b. because it is redundant
c. because it should be defined in another class
d. in order to keep it current
What does the following UML diagram entry mean?
+ setHeight(h : double) : void
a. this is a public attribute named height and is a double data type
b. this is a private method with no parameters and returns a double data type
c. this is a private attribute named height and a double data type
d. this is a public method with a parameter of data type double and does not return a value
methods that operate on an object's field are called
a. instance variables
b. instance methods
c. public methods
d. private methods
The scope of a private instance field is
a. the instance methods of the same class
b. inside the class, but not inside any method
c. inside the parenthesis of a method heater
d. the method in which they are defined
A constructor
a. always accepts two arguments
b. has return type of void
c. has the same name as the class
d. always has an access specifier of private
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!";
Two or more methods in a class may have the same name as long as
a. they have different return types
b. they have different parameter lists
c. they have different return types, but the same parameter list
d. you cannot have two methods with the same name
given the following code, what will be the value of final amount when it is displayed?
public class;
{
private int orderNum;
private double orderAmount;
private orderDiscount;
}
public Order(int orderNumber, double orderAmt, double orderDisc)
{
orderNum = orderNumber;
orderAmount = orderAmt;
orderDiscount = orderDisc;
}
public int getOrderAmount()
{
return orderAmount;
}
public int getOrderDisc()
{
return orderDisc;
}
}
public class Customerorder
{
public static void main(String[] args)
{
int ordNum = 1234;
double ordAmount = 500.00;
double discountPer = .1;
Order order;
double finalAmount = order.getOrderAmount() - order.getOrderAmount() * order.getOrderDisc();
System.out.println("Final order amount = $" + finalAmount);
____ is a library of classes that do not replace _____ but provide an improved alternative for creating GUI applications
a. AWT; Swing
b. Swing; AWT
c. JFC; AWT
d. JFC; Swing
Programs that operate in a GUI must be
a. event driven
b. in color
c. dialog boxes
d. layout managers
In GUI terminology, a container that can be displayed as a window is known as a
a. message dialog
b. buffer
c. Swing package
d. Frame
To end an application, pass this as the argument to the JFrame class's setDefaultCloseOperation() method
a. END_ON_CLOSE
b. JFrame.END_ON_CLOSE
c. JFrame.EXIT_ON_CLOSE
d. JFrame.CLOSE_NOT_HIDE
The minimize button, maximize button, and close button on a window are sometimes referred to as
a. operations buttons
b. sizing buttons
c. decorations
d. display buttons
To use the action listener interface, as well as other event listener interfaces, you must have the following import statement in your code
a. import java.swing;
b. import java.awt;
c. import java.awt.*;
d. import java.awt.event.*;
When you write an action listener class for JButton component it must
a. have a method named buttonClicked
b. implement the ActionLIstener interface
c. have a method named actionPerformed which must take an argument of the ActionEvent type
d. Both b and c.
In a swing application, you create a frame object from the
a. Jlabel class
b. JFrame class
c. Jpanel class
d. AbstractButton class
To use the color class, which is used to set the foreground and background of various objects, use the following import statement
a. import java.swing;
b. import java.awt;
c. import java.awt.*;
d. import java.awt.event.*;
This layout arranges components in rows
a. GridLayout
b. BorderLayout
c. FlowLayout
d. RegionLayout
This layout manager arranges components in regions named north, south, east, west, and center
a. GridLayout
b. BorderLayout
c. FlowLayout
d. RegionLayout
If panel1 references a JPanel object, which of the following statements adds the GridLayout to it?
a. panel.setLayout(new (GridLayout(2,3));
b. panel.addLayout(new(GridLayout(2,3));
c. panel.GridLayout(2,3);
d. panel.attachLayout(GridLayout(2,3));
When using the BorderLayout manager, how many components can each region hold?
a. 1
b. 2
c. 5
d. No limit
The GridLayout manager limits each cell to only one component to put two or more components in a cell do this
a. Resize the cells so they can hold more
b. You can nest panels inside the cells, and add other components to the panels
c. The statement is false. The GridLayout manager does not have this restriction
d. Resize the components to fit in the cell
Which of the following statements is not true?
a. Radio buttons are round and check boxes are square.
b. Radio buttons are often grouped together and are mutually exclusive; Check boxes are not
c. Radio buttons and check boxes both implement the ActionListener interface
d. They are all true
How many radio buttons can be selected at the same time as the result of the following code?
hours = new JRadioButton("Hours");
minutes = new JRadioButton("minutes");
seconds = new JRadioButton("Seconds");
days = new JRadioButton("Days");
months = new JRadioButton("months);
years = new JRadioButton("years");
timeOfDayButtonGroup = new ButtonGroup();
dateButtonGroup = new ButtonGroup();
timeOfDayButtonGroup.add(hours);
timeOfDayButtonGroup.add(minutes);
timeOfDayButtonGroup.add(Seconds);
dateButtonGroup.add(months);
dateButtonGroup.add(years);
dateButtonGroup.add(days);
a. 1
b. 2
c. 3
d. 4
Assume that radio references a JRadioButton object. To click the radio button in code, use the following statement.
a. radio.Click();
b. Click(radio);
c. Click(radio, true);
d. radio.doClick();
The variable panel references a JPanel object. The variable bGroup references a ButtonGroup object. which contains several button components. If you want to add the buttons to the panel
a. use the statement, panel.add(bGroup);
b. use the statement, bGroup.add(panel);
c. use the statement, Panel panel = new Panel(bGroup);
d. add each button to panel one at a time, e.g. panel.add(button1);
what does the following statement do?
double [] array1 = new double[10];
a. Declares array1 to be a reference to an array of double values
b. Creates an instance of an array of 10 double values
c. Will allow valid subscripts in the range of 0 - 9
d. All of the above
what will be the value of x[8] after the following code has been executed?
final int SUB = 12;
int () x = new int[SUB];
int y = 100;
for(int i = 0; i = SUB; i++)
{
x[i] = y;
y+=10;
}
a. 170
b. 180
c. 190
d. 200
what will be the results of the following code?
final int ARRAY_SIZE = 5;
float[] x = float(ARRAY_SIZE);
for(int i = 1; 1 <= ARRAY_SIZE; i++);
{
x[1] = 10.0
}
a. All the values in the array are initialized to 10.0
b. All the values, except the first, are set to 10.0
c. An error will occur when the program runs.
d. There will be a compilation error
what would be the results of the following code?
int[] x = {55, 33, 88, 22, 99, 11, 44, 55, 77};
int a = 10;
if( x[2] > x[5] )
a = 5;
else
a = 8;
a. a = 5
b. a = 8
c. a = 10
d. This is a compilation error, you cannot compare array elements
what would be the results after the following code was executed?
int[] x = (23, 55, 83, 19);
int[] y = (36, 78, 12, 24);
for(int a = 0; a < x.length; a++)
{
x[a] = y[a];
y[a] = x[a];
}
a. x[] = {36, 78, 12, 24} and y[] = {23, 55, 83, 19}
b. x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
c. x[] = {23, 55, 83, 19} and y[] = {23, 55, 83, 19}
d. This is a compilation error
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
When an array is passed to a method
a. a reference to the array is passed
b. it is passed just as an object
c. the method has direct access to the original array
d. All of the above
what would be the results of the following code
int[] array1 = new int[25];
int value = array1[0];
for(int a = 1; a < array1.length; a++)
{
if(array1[a] < value)
value = array1[a];
}
a. value contains the highest value in array1
b. value contains the lowest value in array1
c. value contains the sum of all the values in array1
d. value contains the average of the values in array1
What do you normally use with a partially filled array?
a. A class that does nothing but manage the array
b. An accompanying parallel array
c. An accompanying integer value that holds the number of items stored in the array
d. An accumulator
To return any array of long values from a method, use this as the return type for the method
a. long
b. long[]
c. long[ARRAY_SIZE]
d. []long
In memory, an array of String objects
a. consists of elements, each of which is a reference to a String object.
b. is always implemented as a ragged array.
c. consists of elements, each of which is a String object.
d. must be initialized when the array is declared.
Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement:
a. str.uppercase();
b. str[0].upperCase();
c. str.toUpperCase();
d. str[0].toUpperCase();
The sequential search algorithm
a. requires the array to be ordered
b. must always be implemented as a method
c. uses a loop to sequentially step through an array, starting with the first element
d. will not execute, if the element is not in the array
In order to do a binary search on an array
a. the values of the array must be numeric
b. the array must first be sorted in ascending order
c. you must first do a sequential search of the array to assure the element you are looking for is there
d. There are no requirements
what is the value of scores [2] [3] in the following array?
int [] [] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} };
a. 94
b. 84
c. 93
d. 95
if numbers is a two-dimensional array, which of the following would give the length of row r?
a. numbers.length
b. numbers.length[r]
c. numbers[r].length[r]
d. numbers[r].length
which of the following is a correct method header for receiving a two-dimensional array as an argument?
a. public static void passArray(int[1,2])
b. public static void passArray(int [][])
c. public static void passArray(int[1],[2])
d. public static void passArray(int[], int[])
A ragged array is
a. a two-dimensional array for which the number of rows is unknown
b. a one-dimensional array for which the number of elements is unknown
c. a two-dimensional array where the rows are of different lengths
d. There is no such thing as a ragged array