CSE110- Ch8 Reading Quiz

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which operator should you use to test whether an object reference is null? a) == b) >= c) <= d) =

==

Which of the following statements about constructors is NOT correct? a) A constructor must have the same name as the class name. b) A call to a constructor must always have construction parameters. c) A constructor initializes the instance variables of an object. d) A class can have more than one constructor.

A call to a constructor must always have construction parameters.

Which of the following statements about classes is correct? a) A class is an object that can be manipulated by a program. b) A class describes a set of objects with the same behavior. c) Class is another name for a method. d) A class can contain only methods.

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

Which of the following statements about constructors is correct? a) A class can have only one constructor. b) A constructor should always return a value. c) A class must have at least one constructor supplied by the programmer. d) A constructor must have the same name as the class.

A constructor must have the same name as the class.

Which of the following statements about class properties is correct? a) A setter method is used to retrieve the value of a class property. b) A getter method is used to assign the value of a class property. c) A setter method is used to assign the value of a class property. d) You cannot assign values to class properties.

A setter method is used to assign the value of a class property.

Which of the following statements about testing a class is correct? a) A unit test verifies that only one method within a class works correctly. b) A unit test verifies that a class works correctly when it is in a complete program. c) A unit test verifies that a class works correctly in isolation, outside a complete program. d) A unit test does not need to know what results are expected.

A unit test verifies that a class works correctly in isolation, outside a complete program.

Which of the following are considered members of a class? a) Private instance variables and methods. b) All instance variables and methods. c) Non-static instance variables and methods. d) Public instance variables and methods.

All instance variables and methods.

Which of the following statements about classes is correct? a) All instance variables and most instance methods should be declared as public. b) All instance variables and most instance methods should be declared as private. c) All instance variables should be declared as public and most instance methods should be declared as private. d) All instance variables should be declared as private and most instance methods should be declared as public.

All instance variables should be declared as private and most instance methods should be declared as public.

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? a) Motorcycle myBike; b) Motorcycle myBike = new Motorcycle(); c) myBike.new(Motorcycle); d) Motorcycle.new(myBike);

Motorcycle myBike = new Motorcycle();

Which type of method modifies the object on which it is invoked? a) Constructor method. b) Static method. c) Accessor method. d) Mutator method.

Mutator method.

Which of the following statements about a class is correct? a) A class should not have private instance variables. b) Private instance variables are the interface to the class. c) Private instance variables hide the implementation of a class from the class user. d) Private instance variables should rarely be used in classes.

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

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? a) Rocket myRocket; b) Rocket myRocket = new Rocket(); c) myRocket.new(Rocket); d) Rocket.new(myRocket);

Rocket myRocket = new Rocket();

Consider the following code snippet: public class Vehicle { private String type; private int numAxles; public Vehicle(String vehicleType, int VehicleAxles) { . . . } public Vehicle(String vehicleType) { . . . } } What is wrong with this code? a) There must be a default constructor with no arguments. b) A class cannot have more than one constructor. c) If a class has more than one constructor, each one should have a unique name. d) There is nothing wrong with this code.

There is nothing wrong with this code.

Consider the following code snippet: public class Vehicle { private String type; private int numAxles; public Vehicle(String vehicleType, int VehicleAxles) { . . . } } Which of the following statements can be used to create an object of type Vehicle? a) Vehicle anAuto = new Vehicle(); b) Vehicle anAuto = new Vehicle(2, "SUV"); c) Vehicle anAuto = new Vehicle("SUV", "2"); d) Vehicle anAuto = new Vehicle("SUV", 2);

Vehicle anAuto = new Vehicle("SUV", 2);

Given the following class definition, which of the following are considered part of the class's public interface? public class Motorcycle { public static final int WHEEL_COUNT = 2; private int rpmRating; public void updatePrice(double increase) {...} private String designCode() {...} } a) rpmRating and designCode b) WHEEL_COUNT and designCode c) WHEEL_COUNT and updatePrice d) updatePrice and designCode

WHEEL_COUNT and updatePrice

Private instance variables ___. a) can only be accessed by methods of a different class b) can only be accessed by methods of the same class c) cannot be accessed by methods of the same class d) can only be accessed by the constructor of the class

can only be accessed by methods of the same class

Which of the following is a mutator method of the CashRegister class used in the textbook? a) getTotal b) getCount c) clear d) The CashRegister class does not have any mutator methods.

clear

Given the following class: public class Coin { private String coinName; private double coinValue; . . . } Consider the following code snippet that utilizes the Coin class: Coin coin1 = new Coin("dime", 0.10); Coin coin2 = coin1; coin2.setValue(0.15); Which of the following statements is correct? a) coin1 has a value of 0.10 and coin2 has a value of 0.15. b) coin1 and coin2 both have the value of 0.10. c) coin1 and coin2 both have the value of 0.15. d) coin2 does not have any data in the coinName variable

coin1 and coin2 both have the value of 0.15.

Consider the following code snippet: Coin coin1 = new Coin("dime", 0.10); Coin coin2 = new Coin("dime", 0.10); Which of the following statements is correct? a) coin1 and coin2 contain references to the same object. b) coin1 and coin2 refer to the same object. c) coin1 and coin2 contain the same memory location. d) coin1 and coin2 each have their own set of instance variables

coin1 and coin2 each have their own set of instance variables

Consider the following code snippet: Coin coin1 = new Coin("dime", 0.10); Coin coin2 = coin1; Which of the following statements is NOT correct? a) coin1 and coin2 are object references. b) coin1 and coin2 refer to the same object. c) coin1 and coin2 contain the same memory location. d) coin1 and coin2 each have their own set of instance variables.

coin1 and coin2 each have their own set of instance variables.

Consider the following code snippet: Coin coin1 = null; System.out.println("Value of coin = " + coin1.getValue()); What is wrong with this code? a) coin1 does not refer to an object and will result in an error at run time. b) You cannot concatenate a numeric value with a string value. c) The value variable in coin1 has not been set, and will print as 0. d) There is nothing wrong with this code.

coin1 does not refer to an object and will result in an error at run time.

Consider the following code snippet: public int getCoinValue(String coinName) { . . . } Which of the following statements is correct? a) coinName is an implicit parameter. b) coinName is an explicit parameter. c) coinName is the object on which this method is invoked. d) coinName is an instance variable

coinName is an explicit parameter.

Consider the following code snippet: public static class Triangle { public static double getTriangleArea(double heightLen, double baseLen) { . . . } } You are writing a program that needs to use this method. Which of the following statements correctly calls this method? a) Triangle myTriangle = new Triangle(); double area = myTriangle.getTriangleArea(4.0,7.0); b) double area = new Triangle().getTriangleArea(4.0,7.0); c) double area = Triangle.getTriangleArea(4.0, 7.0); d) This method cannot be used outside of the Triangle class.

double area = Triangle.getTriangleArea(4.0, 7.0);

Which statement illustrates the invocation of a static method? a) mySavings.deposit(100); b) double s = Math.sqrt(100); c) deposit(100).mySavings; d) double s = 100.sqrt();

double s = Math.sqrt(100);

Which of the following statements is true regarding classes? a) Each object of a class has a separate copy of each instance variable. b) All objects created from a class share a single set of instance variables. c) Private instance variables can be accessed by any user of the object. d) Public instance variables can be accessed only by the object itself.

each object of a class has a separate copy of each instance variable.

Consider the following code snippet: public int getSalary(String empNum) { . . . } Which of the following statements is correct? a) empNum is an implicit parameter. b) empNum is an explicit parameter. c) empNum is the object on which this method is invoked. d) empNum is an instance variable.

empNum is an explicit parameter.

The process of hiding object data and providing methods for data access is called ____. a) documentation b) encapsulation c) implementation d) initialization

encapsulation

) Input to a method enclosed in parentheses after the method name is known as ____. a) implicit parameters b) interfaces c) explicit parameters d) return values

explicit parameters

Which of the following is an accessor method of the CashRegister class used in the textbook? a) getTotal b) addItem c) clear d) The CashRegister class does not have any accessor methods.

getTotal

The object on which a method is invoked is called the ____. a) interface b) procedure c) implicit parameter d) explicit parameter

implicit parameter

When an object is created from a class, the object is called a/an ____ of the class. a) child b) constructor c) instance d) subclass

instance

Each object of a class has a separate copy of each ___. a) method b) instance variable c) constructor d) class

instance variable

Data required for an object's use are stored in ____. a) local variables b) instance variables c) parameters d) methods

instance variables

The public constructors and methods of a class form the public _____ of the class. a) interface b) initialization c) implementation d) encapsulation

interface

The utility that formats program comments into a set of documents that you can view in a Web browser is called ____. a) javadoc b) javac c) javad d) java

javadoc

Which of the following lists the correct order of items in an instance method declaration? a) the return type, the name of the method, and a list of the parameters (if any) b) modifiers, the type of the instance variable, and the name of the instance variable c) the type of the instance variable, modifiers, and a list of the parameters (if any) d) modifiers, a return type, a method name, and a list of the parameters (if any)

modifiers, a return type, a method name, and a list of the parameters (if any)

Insert the missing code in the following code fragment. This fragment is intended to implement a method to increase the speed of the motor by one step if possible. public class Motor { public static final STOPPED = 0; public static final SLOW = 1; public static final MEDIUM = 2; public static final FAST = 3; private int motorSpeed; . . . public void increaseMotorSpeed() { if(motorSpeed < FAST) { ________ } } } a) motorSpeed ++; b) motorSpeed = SLOW; c) motorSpeed = MEDIUM; d) motorSpeed = FAST;

motorSpeed ++;

Insert the missing code in the following code fragment. This fragment is intended to implement a method to set the state of the object. public class Motor { public static final STOPPED = 0; public static final PAUSED = 1; public static final RUNNING = 2; private int motorState; . . . public void stopMotor() { ________ } } a) motorState++; b) motorState = STOPPED; c) motorState = PAUSED; d) motorState = RUNNING;

motorState = STOPPED;

A method in a class that modifies information about an object is called a/an ____ method. a) mutator b) accessor c) void d) constructor

mutator

) The ____ operator is used to construct an object from a class. a) add b) create c) new d) construct

new

) Which choice indicates that a string variable refers to no string? a) nil b) "" c) null d) empty

null

Given the following class definition, which of the following are NOT considered part of the class's public interface? public class CashRegister { public static final double DIME_VALUE = 0.1; private static int objectCounter; public void updateDimes(int dimes) {...} private boolean updateCounter(int counter) {...} } a) objectCounter and updateCounter b) DIME_VALUE and objectCounter c) DIME_VALUE and updateDimes d) updateDimes and updateCounter

objectCounter and updateCounter

You should declare all instance variables as ___. a) protected b) class c) public d) private

private

Which of the following declares a rpmRating instance variable for a Motor class that stores an integer value? a) private integer rpmRating; b) private int rpmRating; c) public integer rpmRating; d) public int rpmRating;

private int rpmRating;

Which of the following declares a sideLength instance variable for a Square class that stores an integer value? a) private integer sideLength; b) private int sideLength; c) public integer sideLength; d) public int sideLength;

private int sideLength;

You have created an Employee class. You wish to have a unique, sequential employee number assigned to each new Employee object that is created. Which of the following declarations, if added to the Employee class, would allow you to determine which number was last assigned when you are creating a new Employee object? a) private static int lastAssignedEmpNum = 500; b) public int lastAssignedEmpNum = 500; c) private int lastAssignedEmpNum = 500; d) public static int lastAssignedEmpNum = 500;

private static int lastAssignedEmpNum = 500;

You have created a Student class. You wish to have a unique, sequential student number assigned to each new Student object that is created. Which of the following declarations, if added to the Student class, would allow you to determine which number was last assigned when you are creating a new Student object? a) private static int lastAssignedStudentNum = 1500; b) public int lastAssignedStudentNum = 1500; c) private int lastAssignedStudentNum = 1500; d) public static int lastAssignedStudentNum = 1500;

private static int lastAssignedStudentNum = 1500;

You are creating a class named Employee. Which statement correctly declares a constructor for this class? a) public Employee() b) public void Employee() c) void Employee() d) new Employee()

public Employee()

Complete the following code snippet to create a constructor that will initialize the class instance variables shown using data provided by the program which is creating an object from this class. public class Employee { private String empID; private boolean hourly; _______________________ { . . . } } Which of the following statements can be used to create an object of type Employee? a) public Employee(String employeeID, boolean isHourly) b) public Employee(employeeID, isHourly) c) public Employee(empID, Hourly) d) public Employee()

public Employee(String employeeID, boolean isHourly)

Insert the missing code in the following code fragment. This fragment is intended to implement a method to get the value stored in an instance variable. public class Vehicle { private String model; private double rpm; . . . _______ { return model; } } a) public void setModel(String modelName) b) public void getModel() c) public String getModel() d) public String setModel(String modelName)

public String getModel()

You are creating a class named Vessel. Which statement correctly declares a constructor for this class? a) public Vessel() b) public void Vessel() c) void Vessel() d) new Vessel()

public Vessel()

Insert the missing code in the following code fragment. This fragment is intended to implement a method to get the value stored in an instance variable. public class Employee { private String empID; private boolean hourly; . . . _______ { return hourly; } } a) public void setHourly(String isHourly) b) public void getHourly() c) public boolean getHourly() d) public boolean setHourly(boolean isHourly)

public boolean getHourly()

Insert the missing code in the following code fragment. This fragment is intended to implement a method to set the value stored in an instance variable. public class Employee { private String empID; private boolean hourly; . . . _______ { hourly = isHourly; } } a) public void setHourly(String isHourly) b) public void getHourly() c) public boolean getHourly() d) public boolean setHourly(boolean isHourly)

public boolean setHourly(boolean isHourly)

Consider the following code snippet: public class Student { private static int lastAssignedStudentNum = 1500; { . . . } } Which of the following statements about this code is correct? a) Each object created from this class will have its own lastAssignedStudentNum variable. b) All objects created from this class will share the lastAssignedStudentNum variable. c) The lastAssignedStudentNum variable's value cannot be changed. d) You cannot assign a value to a static variable

All objects created from this class will share the lastAssignedStudentNum variable.

Which of the following statements about instance methods is correct? a) An instance method should always be declared as public. b) An instance method should always be declared as private. c) An instance method should be declared as public only if it is a helper method. d) An instance method should be declared as private only if it is a helper method.

An instance method should be declared as private only if it is a helper method.

Given the following class definition, which of the following are considered part of the class's public interface? public class CashRegister { public static final double DIME_VALUE = 0.1; private static int objectCounter; public void updateDimes(int dimes) {. . .} private boolean updateCounter(int counter) {. . .} } a) objectCounter and updateCounter b) DIME_VALUE and objectCounter c) DIME_VALUE and updateDimes d) updateDimes and updateCounter

DIME_VALUE and updateDimes

Consider the following code snippet: public class Employee { private String empID; private boolean hourly; public Employee(String employeeID, boolean isHourly) { . . . } } Which of the following statements can be used to create an object of type Employee? a) Employee anAuto = new Employee(); b) Employee anAuto = new Employee(10548, true); c) Employee anAuto = new Employee("10548", true); d) Employee anAuto = new Employee(10548, "true");

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

Which of the following statements about encapsulation is correct? a) Encapsulation enables changes to the public interface without affecting users of the class. b) Encapsulation prohibits changes to the implementation details to ensure that users of the class will not be affected. c) Encapsulation enables changes to the implementation details without affecting users of the class. d) Encapsulation provides an easier means of transporting class information.

Encapsulation enables changes to the implementation details without affecting users of the class.

Which statement about instance variables is correct? a) Instance variables must be declared within a method. b) Instance variables must be declared inside the class, but outside any method. c) Instance variables may be declared inside the class, or inside a method. d) Instance variables must be declared outside the class

Instance variables must be declared inside the class, but outside any method.

Consider the following class: public class Auto { private String make; private String model; private String year; public Auto(String aMake, String aModel, String aYear) { make = aMake; model = aModel; year = aYear; } public String calcMileage(double milesDriven, double gasUsed) { double milage = milesDriven/gasUsed; return mileage.toString(); } } Which of the following code snippets will correctly create an object of type Auto and display its mileage? a) myAuto = new Auto(); System.out.println(myAuto.calcMileage(246.0, 15.8)); b) Auto myAuto = new Auto(); System.out.println(myAuto.calcMileage(246.0, 15.8)); c) Auto myAuto = new Auto("2011", "Ford", "Focus"); System.out.println(myAuto.calcMileage(246.0, 15.8)); d) Auto myAuto = new Auto("Ford", "Focus", "2011"); System.out.println(myAuto.calcMileage(246.0, 15.8));

Auto myAuto = new Auto("Ford", "Focus", "2011"); System.out.println(myAuto.calcMileage(246.0, 15.8));

Consider the following class: public class Auto { private String make; private String model; private String year; public Auto(String aMake, String aModel, String aYear) { make = aMake; model = aModel; year = aYear; } public String getInfo() { return year + " " + make + " " + model; } } Which of the following code snippets will correctly create an object of this class and display its information? a) myAuto = new Auto(); System.out.println(myAuto.getInfo()); b) Auto myAuto = new Auto(); System.out.println(myAuto.getInfo()); c) Auto myAuto = new Auto("Ford", "Focus", "2011"); System.out.println(myAuto.getInfo()); d) Auto myAuto = new Auto("2011", "Ford", "Focus"); System.out.println(myAuto.getInfo());

Auto myAuto = new Auto("Ford", "Focus", "2011"); System.out.println(myAuto.getInfo());

Which statement calls a constructor with no construction parameters? a) Circle c = new Circle(); b) Circle c = new Circle; c) Circle c = Circle() d) A call to a constructor must have construction parameters.

Circle c = new Circle();

Which of the following statements about objects is correct? a) An object defines only the methods for a class. b) Every object has its own set of data and a set of methods to manipulate the data. c) An object is a sequence of instructions that performs a task. d) All entities, even numbers, are objects.

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

What type of method does NOT operate on an object? a) private b) static c) final d) instance

static

Consider the following code snippet: public class Coin { private String coinName; . . . } Which of the following statements is correct? a) The coinName variable can be accessed by any user of a Coin object. b) The coinName variable can be accessed only by methods of the Coin class. c) The coinName variable can be accessed only by methods of another class. d) The coinName variable cannot be accessed at all because it is private.

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? a) The compiler will generate a constructor with arguments for each class instance variable and will initialize all of the class instance variables. b) The compiler will generate a constructor with no arguments. c) The compiler will generate a constructor with arguments for each class instance variable. d) The class code will not compile.

The compiler will generate a constructor with no arguments.

Consider the following code snippet: public class Vehicle { private String type; private int numAxles; public void Vehicle(String vehicleType, int VehicleAxles) { . . . } } What is wrong with this code? a) There must be a default constructor with no arguments. b) The class instance variables must be initialized in the declaration statements. c) The constructor declaration must have a return type of String. d) The constructor declaration must not have any return type.

The constructor declaration must not have any return type.

Consider the following code snippet: public class Vehicle { private String type; public String Vehicle(String type) { . . . } } What is wrong with this code? a) The class instance variable type must be initialized when it is declared. b) The constructor must not have any arguments. c) The constructor must not have a return type declared. d) The constructor's return type must be void.

The constructor must not have a return type declared.

Consider the following code snippet: public class Vessel { private String type; public String Vessel(String type) { . . . } } What is wrong with this code? a) The class instance variable type must be initialized when it is declared. b) The constructor must not have any arguments. c) The constructor must not have a return type declared. d) The constructor's return type must be void.

The constructor must not have a return type declared.

Consider the following code snippet: public class Employee { private String empName; . . . } Which of the following statements is correct? a) The empName variable can be accessed by any user of an Employee object. b) The empName variable can be accessed only by methods of the Employee class. c) The empName variable can be accessed only by methods of another class. d) The empName variable cannot be accessed at all because it is private.

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

Consider the following code snippet: public class Coin { private String coinName; public String getCoinValue() { . . . } } Which of the following statements is correct? a) The getCoinValue method can be accessed by any user of a Coin object. b) The getCoinValue method can be accessed only by methods of the Coin class. c) The getCoinValue method can be accessed only by methods of another class. d) The getCoinValue method cannot be accessed at all.

The getCoinValue method can be accessed by any user of a Coin object.

Consider the following code snippet: public class Employee { private String empName; public String getEmpName() { . . . } } Which of the following statements is correct? a) The getEmpName method can be accessed by any user of an Employee object. b) The getEmpName method can be accessed only by methods of the Employee class. c) The getEmpName method can be accessed only by methods of another class. d) The getEmpName method cannot be accessed at all.

The getEmpName method can be accessed by any user of an Employee object.

Consider the following code snippet: public class Coin { private String coinName; private int coinValue; public Coin() { } . . . } Which statement reflects the action performed when the constructor to Coin is called? a) The variable coinName will be initialized to "" and the variable coinValue will be initialized to 0. b) The variable coinName will be initialized to "null" and the variable coinValue will be initialized to 0. c) The variable coinName will not be initialized but the variable coinValue will be initialized to 0. d) The variable coinName will be initialized to null and the variable coinValue will be initialized to 0.

The variable coinName will be initialized to null and the variable coinValue will be initialized to 0.

Consider the following code snippet: public class Employee { private String empID; private boolean hourly; public Employee() { } . . . } Which statement reflects the action performed when the constructor to Employee is called? a) The variable empID will be initialized to "" and the variable hourly will be initialized to false. b) The variable empID will be initialized to "null" and the variable hourly will be initialized to true. c) The variable empID will not be initialized but the variable hourly will be initialized to false. d) The variable empID will be initialized to null and the variable hourly will be initialized to false.

The variable empID will be initialized to null and the variable hourly will be initialized to false.

Consider the following code snippet: public class Vehicle { private String type; private int numAxles; public Vehicle() { } . . . } Which statement reflects the action performed when the constructor to Vehicle is called? a) The variable type will be initialized to "" and the variable numAxles will be initialized to 0. b) The variable type will be initialized to "null" and the variable numAxles will be initialized to 0. c) The variable type will not be initialized but the variable numAxles will be initialized to 0. d) The variable type will be initialized to null and the variable numAxles will be initialized to 0.

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

Which of the following statements about encapsulation is correct? a) To use encapsulation, you must provide a set of private methods in the class. b) To use encapsulation, the class must contain only public methods in the class. c) To use encapsulation, the implementation details must be public. d) To use encapsulation, you must provide a set of public methods in the class and hide the implementation details.

To use encapsulation, you must provide a set of public methods in the class and hide the implementation details.

Which of the following statements about classes is correct? a) 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. b) When programmers work with an object of a class, they must understand how the object stores its data and how its methods are implemented. c) When programmers work with an object of a class, they must understand only how the object stores its data. b) When programmers work with an object of a class, they must understand only how the object's methods are implemented.

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 using data values in a class is NOT correct? a) You can use an instance variable's data value in an instance method. b) You can use the argument of an instance method in that method. c) You can use a global constant's value in an instance method. d) You can use the argument of any instance method in any other method.

You can use the argument of any instance method in any other method.

A method in a class that returns information about an object but does not change the object is called a/an ____ method. a) mutator b) accessor c) void d) constructor

accessor

An instance variable declaration consists of ____. a) the return type, the name of the method, and a list of the parameters (if any). b) an access specifier, the type of the instance variable, and the name of the instance variable. c) an access specifier, a list of the parameters (if any), and the body of the method. d) the type of the instance variable, an access specifier, a list of the parameters (if any), and the body of the method.

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

Consider the following code snippet: public class Course { private int studentCount; . . . } Which of the following methods would correctly keep track of the total number of enrollees in a course? a) public void addEnrollees(int newEnrollees) { studentCount = newEnrollees } b) public void addEnrollees(int newEnrollees) { studentCount = studentCount + newEnrollees } c) public void addEnrollees(int newEnrollees) { newEnrollees = studentCount } d) public void addEnrollees(int newEnrollees) { newEnrollees = newEnrollees + studentCount }

public void addEnrollees(int newEnrollees) { studentCount = studentCount + newEnrollees }

Consider the following code snippet: public class Transaction { private int transactionCount; . . . } Which of the following methods would correctly keep track of the total number of transactions? a) public void addTransactions(int newTransactions) { transactionCount = newTransactions } b) public void addTransactions(int newTransactions) { transactionCount = transactionCount + newTransactions } c) public void addTransactions(int newTransactions) { newTransactions = transactionCount } d) public void addTransactions(int newTransactions) { newTransactions = newTransactions + transactionCount }

public void addTransactions(int newTransactions) { transactionCount = transactionCount + newTransactions }

Consider the following code snippet: public class AutoRace { private int lapCount; private double totalTime; . . . } Which of the following completeLap methods would correctly track how many laps occurred? a) public void completeLap(double lapTime) { totalTime = totalTime + lapTime; } b) public void completeLap(double lapTime) { totalTime = totalTime + lapTime; lapCount ++; } c) public void completeLap(double lapTime) { totalTime = totalTime + lapTime; lapCount = lapCount + lapTime; } d) public void completeLap(double lapTime) { totalTime = lapCount + lapTime; }

public void completeLap(double lapTime) { totalTime = totalTime + lapTime; lapCount ++; }

Consider the following code snippet: public class BankAccount { private int transactionCount; private double balance; . . . } Which of the following deposit methods would correctly track how many deposits occurred? a) public void deposit(double amount) { balance = balance + amount; } b) public void deposit(double amount) { balance = balance + amount; transactionCount ++; } c) public void deposit(double amount) { balance = balance + amount; transactionCount = transactionCount + amount; } d) public void deposit(double amount) { balance = transactionCount + amount; }

public void deposit(double amount) { balance = balance + amount; transactionCount ++; }

Consider the following code snippet: public class Vehicle { private String model; private double rpm; . . . } Which of the following methods would correctly remove the values of the class instance variables? a) public void reset() { model = null; rpm = 0; } b) public void reset() { model.clear(); rpm = 0; } c) public void reset(String aModel, double theRpm) { model = aModel; rpm = theRpm; } d) public void reset("",0) { }

public void reset() { model = null; rpm = 0; }

Insert the missing code in the following code fragment. This fragment is intended to implement a method to assign a value to an instance variable. public class Vehicle { private String model; private double rpm; . . . _______ { model = modelName; } } a) public void setModel(String modelName) b) public void getModel() c) public String getModel() d) public String setModel(String modelName)

public void setModel(String modelName)

Given the following class definition, which of the following are NOT considered part of the class's public interface? public class Motorcycle { public static final int WHEEL_COUNT = 2; private int rpmRating; public void updatePrice(double increase) {...} private String designCode() {...} } a) rpmRating and designCode b) WHEEL_COUNT and designCode c) WHEEL_COUNT and updatePrice d) updatePrice and designCode

rpmRating and designCode

Consider the following code snippet: 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? a) setCoinName is an accessor method. b) setCoinName is a mutator method. c) getCoinName is a mutator method. d) getCoinValue is a mutator method.

setCoinName is a mutator method.

Consider the following code snippet: 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? a) setVehicleAttributes is an accessor method. b) setVehicleAttributes is a mutator method. c) getVehicleAttributes is a mutator method. d) getModelName is a mutator method.

setVehicleAttributes is a mutator method.

Consider the following code snippet: 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? a) setVehicleAttributes is an accessor method. b) setVehicleAttributes is a mutator method. c) getVehicleAttributes is an accessor method. d) getModelName is an accessor method.

setVehicleAttributes is an accessor method.

The this reference refers to ____. a) the explicit parameter b) the method that is running c) the constructor of the object d) the implicit parameter

the implicit parameter

A constructor is invoked when ___ to create an object. a) the class keyword is used b) the class is defined as public c) the new keyword is used d) the class is defined as private

the new keyword is used

Which of the following is NOT part of the declaration of an instance variable? a) the return type b) a modifier specifying the level of access c) the data type d) the name

the return type

Insert the missing code in the following code fragment. This fragment is intended to initialize an instance variable. public class Motor { int motorSpeed; public Motor(int speed) { motorSpeed = speed; } public Motor() { _________; } } Which of the following lines of code will allow the second constructor to call the first constructor? a) this.motorspeed(0); b) this(0); c) this(speed); d) You cannot call a constructor from within another constructor.

this(0);

Insert the missing code in the following code fragment. This fragment is intended to initialize an instance variable. public class Vehicle { int numAxles; public Vehicle(int axles) { numAxles = axles; } public Vehicle() { _________; } } Which of the following lines of code will allow the second constructor to call the first constructor? a) this. numAxles(0); b) this(0); c) this(axles); d) this(numAxles);

this(0);

Insert the missing code in the following code fragment. This fragment is intended to initialize an instance variable. public class Employee { private String empName; . . . public Employee(String empName) { ________ } } a) Employee.empName = empName; b) empName = this.empName; c) this.empName = empName; d) The constructor parameter variable cannot have the same name as an instance variable.

this.empName = empName;

Insert the missing code in the following code fragment. This fragment is intended to initialize an instance variable. public class Motor { private int motorSpeed; . . . public Motor(int motorSpeed) { ________ } } a) Motor.motorSpeed = motorSpeed; b) motorSpeed = this.motorSpeed; c) this.motorSpeed = motorSpeed; d) The constructor parameter variable cannot have the same name as the instance variable

this.motorSpeed = motorSpeed;


Kaugnay na mga set ng pag-aaral

Chapter 20: Genes Within Populations

View Set

GW- Ch 9- CompTIA Security+ (Exam SYO-501)

View Set