Programming 2 Exam 2 Multiple Choice

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Given four JRadioButton objects in a ButtonGroup, how many radio buttons can be selected at the same time?

1

Suppose you push integer elements 1,2,3,4 onto a stack in that order. Then pop an element off the stack and add that element to a queue. You repeat that process three more times. In what order will you remove the elements from the queue?

4,3,2,1

Which of the following is an event source?

A JButton object.

Which of the following statements about a Java interface is NOT true?

A Java interface must contain more than one method.

(code snippet) If a Motorcycle class is created as a subclass of the Vehicle class, which of the following statements is correct?

A Motorcycle object inherits and can directly use the method setVehicleClass but cannot directly use the instance variable manufacturer.

(code snippet) If a Speedboat class is created as a subclass of the Vessel class, which of the following statements is correct?

A Speedboat object inherits and can directly use the method setVesselClass but cannot directly use the instance variable manufacturer

Which of the following statements about constructors is NOT correct?

A call to a constructor must always have construction parameters

Which of the following statements about classes is correct?

A class describes a set of objects with the same behavior.

Which of the following statements about constructors is correct?

A constructor must have the same name as the class.

Which of the following statements about listener classes is true?

A listener class can be declared as an anonymous inner class.

Which of the following statements about event listeners is true?

A single event listener can be used to respond to multiple types of events to which the program wishes to respond

Which of the following statements about stacks is correct?

A stack implements last-in, first-out retrieval.

Which of the following is true regarding subclasses?

A subclass has no access to private instance variables of its superclass

Which of the following is true regarding subclasses?

A subclass inherits methods and instance variables from its superclass

Which of the following is true regarding subclasses?

A subclass may inherit methods and instance variables from its superclass, and may also implement its own methods and declare its own instance variables

Which of the following is true regarding inheritance?

A superclass can force a programmer to override a method in any subclass created from it.

What's the difference between a text field and a text area?

A text field is for a single line of text and a text area is for multiple lines of text.

An event listener for a button must implement the ____ interface.

ActionListener

How do you add two buttons to the south area of a frame using the BorderLayout?

Add them to a panel, then add the panel to the SOUTH

A CashRegister class contains an array list of Coin objects. This is best described as an example of ____.

Aggregation

____ is often described as the has-a relationship.

Aggregation.

Which statement about methods in an interface is true?

All methods in an interface are automatically public.

Which of the following statements about abstract methods is true?

An abstract method has a name, parameters, and a return type, but no code in the body of the method.

Which of the following statements about an interface is true?

An interface has methods but no instance variables.

Consider the following inheritance hierarchy diagram: Which of the following statements is correct?

Auto class inherits from LandVehicle class, and LandVehicle class inherits from Vehicle class

Consider the following inheritance hierarchy diagram: Which of the following statements is correct?

Auto is a subclass of LandVehicle, and LandVehicle is a subclass of Vehicle

What is the default layout manager of the content pane of a JFrame?

BorderLayout

Which statement calls a constructor with no construction parameters?

Circle c = new Circle();

Given the following class definition, which of the following are considered part of the class's public interface?

DIME_VALUE and updateDimes

A UML class diagram would be most useful in visually illustrating which of the following?

Dependencies between classes.

Which of the following statements about a priority queue structure is correct?

Elements must be removed in priority order.

____ are generated when the user presses a key, clicks a button, or selects a menu item.

Events.

Which of the following statements about objects is correct?

Every object has its own set of data and a set of methods to manipulate the data.

What is a general naming convention for a class?

First letter capitalized.

By default, a JPanel uses a _______ layout.

FlowLayout

What is the default layout manager of JPanel?

FlowLayout

Which layout manager places objects left-to-right, and creates a new row only if when the current row cannot accommodate another object?

FlowLayout

Which layout manager places objects left-to-right, row by row into a fixed set of rows and columns?

GridLayout

Which of the following GUI objects generate(s) action events?

I,II, and III

Event listeners are often installed as ____ classes so that they can have access to the surrounding fields, methods, and final variables.

Inner

public class Auto extends Vehicle { . . . public Auto(int numberAxles) { super(numberAxles); } } What does this code do?

It invokes the constructor of the Vehicle class from within the constructor of the Auto class.

public class Motorcycle extends Vehicle { private String model; . . . public Motorcycle(int numberAxles, String modelName) { super(numberAxles); model = modelName; } } What does this code do?

It invokes the constructor of the Vehicle class from within the constructor of the Motorcycle class.

Which of the following statements creates a button with "Calculate" as its label?

JButton button = new JButton("Calculate")

Which GUI element allows text entry from the program user?

JComboBox

Which of the following classes have a user-editable area?

JComboBox

Which statements will create an editable text field and assign "Your choice" to it?

JTextField txt = new JTextField("Your choice ");txt.setEditable(true);

Which of the following statements correctly describes the relationship between the Motorcycle and Vehicle classes?

Motorcycle exhibits the is-a relationship with regard to Vehicle.

You have created a Motorcycle class which has a constructor with no parameters. Which of the following statements will construct an object of this class?

Motorcycle myBike = new Motorcycle();

Which type of method modifies the object on which it is invoked?

Mutator method

You are designing an application to support an automobile rental agency. Which of the following probably should NOT be represented as an object?

Payment amount

Which of the following statements about a class is correct?

Private instance variables hide the implementation of a class from the class user

Which of the following would be an appropriate name for a class used in an inventory application?

Product

____________________ are round and have a black dot when selected.

Radio Buttons

You have created a Rocket class which has a constructor with no parameters. Which of the following statements will construct an object of this class?

Rocket myRocket = new Rocket();

How do you specify what the program should do when the user clicks a button?

Specify the actions to take in a class that implements the ActionListener interface.

public class Vehicle { . . . public void setVehicleClass(double numberAxles) { . . . } } public class Auto extends Vehicle { . . . public void setVehicleClass(int numberAxles) { . . . } } Which of the following statements is correct?

The Auto class overloads the setVehicleClass method.

Which of the following statements is NOT correct?

The Vehicle class can call the setModelName method.

public class Vessel { . . . public void setVesselClass(double numberAxles) { . . . } } public class Speedboat extends Vessel { . . . public void setVesselClass(double numberAxles) { . . . } } Which of the following statements is correct?

The Vessel class overrides the setVesselClass method.

JPanel panel = new JPanel(); JFrame frame = new JFrame(); JButton button = new JButton("Click me"); JLabel label = new JLabel("Show the answer"); frame.add(label); frame.add(button); panel.add(frame); Which of the following statements is true?

The button and label should be added to the panel first, and then the panel should be added to the frame

public class Coin { private String coinName; public String getCoinValue() { . . . } } Which of the following statements is correct?

The coinName variable can be accessed only by methods of the Coin class.

If you do not provide a constructor in a class, which of the following is correct?

The compiler will generate a constructor with no arguments.

public class Employee { private String empName; public String getEmpName() { . . . } } Which of the following statements is correct?

The empName variable can be accessed only by methods of the Employee class.

Which of the following statements about comparing objects is correct?

The equals method is used to compare whether two objects have the same contents

If the Programmer class inherits from the Employee class, and both classes have an implementation of the increaseSalary method with the same set of parameters and the same return type, which statement is correct?

The increaseSalary method of the Programmer class will be executed

Which of the following statements about a priority queue structure is NOT correct?

The insert method is used to add a new element to the priority queue.

Which of the following statements about an inner class is true?

The methods of an inner class can access variables declared in the enclosing scope

If the Auto class inherits from the Vehicle class, and both classes have an implementation of the moveForward method with the same set of parameters and the same return type, which statement is correct?

The moveForward method of the Auto class will be executed.

public class Vehicle { . . . public void setVehicleAtrributes() { . . . } } public class Auto extends Vehicle { . . . public void setVehicleAtrributes() { . . . } } Which of the following statements is correct?

The subclass is overriding a superclass method.

public class Vessel { . . . public void setVesselAtrributes() { . . . } } public class Speedboat extends Vessel { . . . public void setVesselAtrributes() { . . . } } Which of the following statements is correct?

The subclass is overriding a superclass method.

What must a subclass do to modify a private superclass instance variable?

The subclass must use a public method of the superclass (if it exists) to update the superclass's private instance variable.

Assume that the Auto class inherits from the Vehicle class, and neither class has an implementation of the toString() method. Which of the following statements is correct?

The toString() method of the Object class will be used when this code is executed.

Which statement reflects the action performed when the constructor to Vehicle is called?

The variable type will be initialized to null and the variable numAxles will be initialized to 0.

Complete the code in the Auto class method named displayAutoType to return the type data.

This cannot be done unless the Auto class uses a public method in a superclass that returns the type data.

Which of the following statements describing relationships between the Motorcycle, Tire, Engine and Vehicle classes is NOT correct?

Vehicle exhibits the has-a relationship with regards to Motorcycle.

Given the following class definition, which of the following are considered part of the class's public interface?

WHEEL_COUNT and updatePrice

Which of the following statements about classes is correct?

When programmers work with an object of a class, they do not need to know how the object stores its data or how its methods are implemented.

Which of the following statements about inheritance is correct?

You can always use a subclass object in place of a superclass object

Which of the following most likely indicates that you have chosen a good name for your class?

You can tell by the name what an object of the class is supposed to represent

Which of the following statements about events and graphical user interface programs is true?

Your program must indicate the specific types of events to which it wishes to respond.

PriorityQueue<String> stringQueue = new PriorityQueue<>(); What output will be produced when this code is executed?

a,ab,abc,

System.out.print(stringStack.pop() + ","); What output will be produced when this code is executed?

a,abc,ab,

System.out.print(stringQueue.remove() + ","); What output will be produced when this code is executed?

ab,abc,a,

(stack code) What will be printed when this code is executed?

abcdefghi

A method that has no implementation is called a/an ____ method.

abstract

All ____ methods must be implemented when using an interface.

abstract.

A method in a class that returns information about an object but does not change the object is called a/an ____ method.

accessor

To respond to a button event, a listener must supply instructions for the ____ method of the ActionListener interface.

actionPerformed

To associate an event listener with a JButton component, you must use the ___ method of the JButton class.

addActionListener

An instance variable declaration consists of

an access specifier, the type of the instance variable, and the name of the instance variable

Assuming the following declaration, which statement creates an object of type Employee?

anEmp = new Employee("10548", true);

When adding a component to a container with the ____ layout, specify the NORTH, EAST, SOUTH, WEST, or CENTER position.

border

A ________ is a user-interface component with two states: checked and unchecked.

check box

Which of the following is a mutator method of the CashRegister class used in the textbook?

clear

public int getCoinValue(String coinName) { . . . } Which of the following statements is correct?

coinName is an explicit parameter.

A ____ is a combination of a list and a text field.

combo box

A(n) ____ is used when you have a large set of choices.

combo box

User-interface components are arranged by placing them inside ____________________.

containers

Assume that the Auto class inherits from the Vehicle class, and both classes have an implementation of the moveForward method with the same set of parameters and the same return type. The process for determining which class's moveForward method to execute is called ____.

dynamic lookup.

public int getSalary(String empNum){ } Which of the following statements is correct?

empNum is an explicit parameter

The process of hiding object data and providing methods for data access is called ____.

encapsulation

The methods of a/an ____ describe the actions to be taken when an event occurs.

event listener

Input to a method enclosed in parentheses after the method name is known as ____.

explicit parameters

To create a subclass, use the ____ keyword.

extends

JFrame frame = new JFrame(); JPanel panel = new JPanel(); Which statement would add the panel to the frame?

frame.add(panel);

Which of the following statements should be added to this code fragment to set the frame size to a width of 400 and a height of 200? final int FRAME_WIDTH = 400; final int FRAME_HEIGHT = 200; JFrame frame = new JFrame();

frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);

Based on the following statement, which of the following statements sets the title of the frame: JFrame frame = new JFrame();

frame.setTitle("An Empty Frame");

Which statement should be added to this code fragment to ensure that the frame is shown? JFrame frame = new JFrame();

frame.setVisible(true);

When added to the code below, which statement will set the color of the next item drawn to green?

g.setColor(Color.GREEN);

Which of the following is an accessor method of the CashRegister class used in the textbook?

getTotal

The statement that would add smallButton to the button group in the following code is _________.

group.add(smallButton);

The object on which a method is invoked is called the ____.

implicit parameter

When an object is created from a class, the object is called a/an ____ of the class.

instance

Each object of a class has a separate copy of each ___.

instance variable

Data required for an object's use are stored in ____.

instance variables

The public constructors and methods of a class form the public _____ of the class.

interface

The utility that formats program comments into a set of documents that you can view in a Web browser is called ____.

javadoc

In Java, each container has its own ____________________, which determines how the components are laid out.

layout manager

A method in a class that modifies information about an object is called a/an ____ method.

mutator

Assume that you have declared a queue named myQueue to hold String elements. Which of the following statements will correctly insert an element into myQueue?

myQueue.add("apple");

Assume that you have declared a queue named myQueue to hold String elements. Which of the following statements will correctly delete an element from myQueue?

myQueue.remove();

Assume that you have declared a stack named myStack to hold String elements. Which of the following statements will correctly retrieve the top element from myStack without removing it?

myStack.peek();

Assume that you have declared a stack named myStack to hold String elements. Which of the following statements will correctly remove an element from myStack?

myStack.pop();

Assume that you have declared a stack named myStack to hold String elements. Which of the following statements will correctly add an element to myStack?

myStack.push("apple");

Given the following class definition, which of the following are NOT considered part of the class's public interface?

objectCounter and updateCounter

If a subclass contains a method with the same name as a method in its superclass, but with different parameter types, the subclass method is said to ____ the method of the superclass.

overload.

Place drawing instructions inside the __________ method, which is called whenever the component needs to be repainted.

paintComponent

An inner class can access local variables from the enclosing method only if they are declared as ____.

public

You are creating a class named Employee. Which statement correctly declares a constructor for this class?

public Employee()

You are creating a class named Vessel. Which statement correctly declares a constructor for this class?

public Vessel()

Which of the following indicates that a class named Class1 is a subclass of a class named Class2?

public class Class1 extends Class2

Which of the following indicates that a class named ClassA class is a superclass of the ClassB class?

public class ClassB extends ClassA

You are creating a Motorcycle class that is supposed to be a subclass of the Vehicle class. Which of the following class declaration statements will accomplish this?

public class Motorcycle extends Vehicle

You are creating a Motorcycle class which is supposed to inherit from the Vehicle class. Which of the following class declaration statements will accomplish this?

public class Motorcycle extends Vehicle

You are creating a Motorcycle class which is supposed to use an interface named Measurable. Which of the following class declaration statements will accomplish this?

public class Motorcycle implements Measurable

You wish to create a subclass named PolisherMachine. Which of the following is the correct way to declare this subclass?

public class PolisherMachine extends Machine{public void setRPMs() { . . . }}

Which of the following code snippets denotes that the Rose class inherits from the Flower class?

public class Rose extends Flower

You are creating a Vessel class which is supposed to use an interface named Measurable. Which of the following class declaration statements will accomplish this?

public class Vessel implements Measurable

A queue is a collection that ____.

remembers the order of elements and allows elements to be inserted only at one end and removed only at the other end

A stack is a collection that ____.

remembers the order of elements, and allows elements to be added and removed only at one end.

Given the following class definition, which of the following are NOT considered part of the class's public interface?

rpmRating and designCode

Assume that the Auto class has not implemented its own toString() method. What value will s contain when this code is executed?

s will contain the name of the consumerAuto object followed by a hash code

public class Coin { . . . public void setCoinName(String name) { . . . } public String getCoinName() {. . . } public String getCoinValue() {. . . } } Assuming that the names of the methods reflect their action, which of the following statements about this class is correct?

setCoinName is a mutator method

The JFrame has a content pane with a default BorderLayout manager. Which method allows changing it to a FlowLayout manager?

setLayout

public class Vehicle { . . . public void setVehicleAttributes(String attributes) { . . . } public String getVehicleAtrributes() { . . . } public String getModelName() {. . . } } Assuming that the names of the methods reflect their action, which of the following statements about this class is correct?

setVehicleAttributes is a mutator method

public class Vehicle { . . . public void setVehicleAttributes(String attributes) { . . . } public String getVehicleAtrributes() {. . . } public String getModelName() { . . . } } Assuming that the names of the methods reflect their action, which of the following statements about these instance methods is NOT correct?

setVehicleAttributes is an accessor method.

Insert the missing code in the following code fragment. This fragment is intended to call the Vehicle class's method.

setVehicleClass(2.0);

A class that represents a more specific entity in an inheritance hierarchy is called a/an ____.

subclass

Which reserved word must be used to call a method of a superclass?

super

Consider the following class hierarchy: Complete the code in the Auto class constructor to store the type data.

super(type);

A class that represents the most general entity in an inheritance hierarchy is called a/an ____.

superclass

When using a combo box, the _______ displays the name of the current selection.

text field

Assume that the Programmer class inherits from the Employee class, and both classes have an implementation of the increaseSalary method with the same set of parameters and the same return type. Which class's increaseSalary method is to be executed is determined by ____.

the actual object type.

To test whether an object belongs to a particular type, use ___.

the instanceof operator.

A constructor is invoked when ___ to create an object.

the new keyword is used

If a subclass uses the same method name but different parameter types for a method that appears in its superclass, ____.

the subclass has overloaded its superclass's method

If a subclass defines the same method name and the same parameter types for a method that appears in its superclass, ____.

the subclass has overridden its superclass's method.

Insert the missing code in the following code fragment. This fragment is intended to call the Vessel class's method.

vesselLength(26.0);


संबंधित स्टडी सेट्स

Bio Quiz Chapter 7 UNIT 10 Evolution and Natraul Selection

View Set