Comp sci quiz compendium 8,9,10,12

¡Supera tus tareas y exámenes ahora con Quizwiz!

If the following is from the method section of a UML diagram, which of the statements below is true?+ add(object2:Stock) : Stock a.This is a public method named Stock that adds two objects. b.This is a private method named Stock that adds two objects. c.This is a public method named add that accepts and returns references to objects in the Stock class. d.This is a private method named add that accepts and returns objects of the Stock class.

C. This is a public method named add that accepts and returns references to objects in the Stock class

Replacing inadequate superclass methods with more suitable subclass methods is known as ____ a. method overriding b. method upgrading c. tactical inheritance d.method overloading

a. method overriding

What type of relationship exists between two objects when one object is a specialized version of another object? a."is a" b."has a" c."consists of" d."contains a"

a."is a"

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

a.All instance variables and methods.

In Java it is possible to write a method that will return ________. a.Any of these b.a reference to an object c.a string of characters d.a whole number

a.Any of these

After you have identified a set of classes needed for a program, you should now ____. a.Define the behavior of each class. b.Look for nouns that describe the tasks. c.Begin writing the code for the classes. d.Establish the relationships between the classes.

a.Define the behavior of each class.

Why is it generally considered good practice to minimize dependencies between classes? a.High dependency increases program maintenance and hinders code reuse. b.High dependency implies less interface cohesion. c.Low dependency decreases the probability of code redundancy. d.Low dependencies increases the operational efficiency of a program.

a.High dependency increases program maintenance and hinders code reuse.

Which of the following is true about protected access? a.Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package. b.Protected members cannot be accessed by methods in any other classes. c.Protected members may be accessed by methods in the same package or in a subclass, but only if the subclass is in the same package. d.Protected members are actually named constants.

a.Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package.

When you begin designing a program, you work from a ____, a description of what your program should do. a.Requirements specification b.Blueprint c.UML Diagram d.Recipe

a.Requirements specification

If you have multiple classes in your program that have implemented the same interface in different ways, how is the correct method executed? a.The Java virtual machine must locate the correct method by looking at the class of the actual object. b.You cannot have multiple classes in the same program with different implementations of the same interface. c.The method must be qualified with the class name to determine the correct method. d.The compiler must determine which method implementation to use.

a.The Java virtual machine must locate the correct method by looking at the class of the actual object.

A class becomes abstract when you place the ________ key word in the class definition. a.abstract b.extends c. super d final

a.abstract

A UML class diagram would be most useful in visually illustrating which of the following? a.dependencies between classes. b.the amount of complexity of a class's interface. c.relationships between classes and their interfaces. d.the cohesiveness of a class's interface.

a.dependencies between classes.

A subclass can directly access ________. a.only public and protected members of the superclass b.only public and private members of the superclass c.all members of the superclass d.only protected and private members of the superclass

a.only public and protected members of the superclass

If two methods have the same name but different signatures they are ________. a.overloaded b.superclass methods c.subclass methods d.overridden

a.overloaded

The whole-part relationship created by object aggregation is more often called a(n) ________ relationship. a.inner class b."has a" c.inside class d.extra class

b."has a"

When using CRC cards, UML diagrams should be created ___. a.Prior to discovering classes. b.After you have discovered classes and their relationships. c.During the implementation phase. d.To produce final documentation of the system.

b.After you have discovered classes and their relationships.

During the implementation phase, which of the following statements is true? a.Aggregated classes will yield subclasses. b.Aggregated classes will yield instance variables c.Aggregated classes will yield class packages. d.Aggregated classes will yield interfaces.

b.Aggregated classes will yield instance variables

Consider the following code snippet: public class Motorcycle { private Tire[] tires; . . . } This code is best described as an example of ____. a.Inheritance. b.Aggregation. c.Polymorphism. d.Association.

b.Aggregation.

If a class contains an abstract method ________. a.the method will only have a header, but not a body, and will end with a semicolon b.All of these are true. c.the method cannot be overridden in subclasses d.you must create an instance of the class

b.All of these are true.

Which of the following is true about interface types and abstract classes? a.An interface type cannot be instantiated whereas an abstract class can. b.An interface type cannot have instance variables whereas an abstract class can. c.An abstract class can provide method implementation whereas an interface type cannot. d.An interface type cannot have constants whereas an abstract class can.

b.An interface type cannot have instance variables whereas an abstract class can.

Before you begin designing a solution, you should ____. a.Document the methods that will be needed. b.Gather and document all requirements for the program in plain English. c.Determine the classes that will be needed. d.Create the UML diagrams to represent the classes.

b.Gather and document all requirements for the program in plain English.

Which of the following is not true about static methods? a.They are created by placing the key word static after the access specifier in the method header. b.It is necessary for an instance of the class to be created to execute the method. c.They are often used to create utility classes that perform operations on data but have no need to store and collect data. d.They are called directly from the class.

b.It is necessary for an instance of the class to be created to execute the method.

What is wrong with the following code? public classB extends classA{ public classB(){ int init = 10; super(40); } } a.The method super is not defined. b.The call to the method super must be the first statement in the constructor. c.Nothing is wrong with this code. d.the constructor needs a parameter e.it is missing a copy constructor f.No values may be passed to super.

b.The call to the method super must be the first statement in the constructor.

Assume a class extends another class and implements an interface, both of which define the same method. Which statement is true about this conflict of inherited methods? a.The compiler will generate an error due to the conflict. b.The code compiles but generates an exception at run time due to the conflict. c.The subclass inherits the superclass method and ignores the default method from the interface. d.There is no conflict because interfaces cannot provide method implementation.

b.The code compiles but generates an exception at run time due to the conflict.

Which of the following is a good indicator that a class is overreaching and trying to accomplish too much? a.The class is both cohesive and dependent. b.The public interface refers to multiple concepts c. The class has more constants than methods d. The public interface exposes private features

b.The public interface refers to multiple concepts

If ClassC is derived from ClassB which is derived from ClassA, this would be an example of ________. a.cascading classes b.a chain of inheritance c.multiple interfaces d.linear inheritance

b.a chain of inheritance

When a method's return type is a class, what is actually returned to the calling program? a.the values in the object that the method accessed b.a reference to an object of that class c.an object of that class d.nothing - the return type is simply for documentation in this situation

b.a reference to an object of that class

Which of the following is the operator used to determine whether an object is an instance of a particular class? a.>> b.instanceOf c.isa d.equals

b.instanceOf

When the this variable is used to call a constructor ________ a.it must be the last statement in the constructor making the call b.it must be the first statement in the constructor making the call c.None of these. You cannot use this variable in a constructor call. d.it can be anywhere in the constructor making the call

b.it must be the first statement in the constructor making the call

Classes often correspond to ____ in a requirements description. a.verbs b.nouns c.Dependencies d.Relationships

b.nouns

If you don't provide an access specifier for a class member, the class member is given ________ access by default. a.protected b.package c.public d.private

b.package

A subclass may call an overridden superclass method by ________. a.calling the superclass method first and then calling the subclass method b.prefixing its name with the super key word and a dot (.) c.prefixing its name with the name of the superclass in parentheses d.using the extends key word before the method is called

b.prefixing its name with the super key word and a dot (.)

Which of the following statements declares Salaried as a subclass of PayType? a.public class PayType derives Salaried b.public class Salaried extends PayType c.public class Salaried derivedFrom(PayType) d.public class Salaried implements PayType

b.public class Salaried extends PayType

Given the following method header, what will be returned from the method? public Rectangle getRectangle() a.an object of the class Rectangle b.the address of an object of the Rectangle class c.the values stored in the data members of the Rectangle object d.a graph of a rectangle

b.the address of an object of the Rectangle class

To compare two objects in a class, a.This cannot be done since objects consist of several fields. b.write an equals method that will make a field by field compare of the two objects c.write a method to do a byte-by-byte compare of the two objects d.use the == operator (for example, object1 == object2)

b.write an equals method that will make a field by field compare of the two objects

When you make a copy of the aggregate object and of the objects that it references, ________. a.you are performing a shallow copy b.you are performing a deep copy c.you are performing a nested copy d.a compiler error will occur

b.you are performing a deep copy

A Quiz class contains an array of Question objects. This is best described as an example of ____. a.Association b.Inheritance c.Aggregation d.Cohesiveness

c. Aggregation

Static methods can only operate on ________ fields. a. instance b. local c. static d. global

c. static

Using the given definition of the Measurable interface: public interface Measurable { double getMeasure(); } Consider the following code snippet, assuming that BankAccount has a getBalance method and implements the Measurable interface by providing an implementation for the getMeasure method: Measurable m = new BankAccount(); System.out.println(_________________________); Select the correct expression to display the balance of the bank account. a.m.BankAccount.getBalance() b.m.getBalance() c.((BankAccount) m).getBalance() d.m.super.getBalance()

c.((BankAccount) m).getBalance()

You have determined a need for a Book class and a Page class in your program. Which relationship is most appropriate between these classes? a. Interface implementation b.Dependency c.Aggregation d. Inheritance

c.Aggregation

Which of the following statements about an interface is true? a.An interface has both public and private methods. b.An interface has methods and instance variables. c.An interface has methods but no instance variables. d.An interface has neither methods nor instance variables.

c.An interface has methods but no instance variables.

A protected member of a class may be directly accessed by ________. a.methods in the same package b.methods of the same class c.Any of these d.methods of a subclass

c.Any of these

Assume that the Measurable interface is defined with a static sum method that computes the sum of the Measurable objects passed in as an array and that BankAccount implements the Measurable interface. Also, assume that there is a variable branchAccount that is an object reference to a populated array of BankAccounts objects for a bank branch. Which of the following represents a correct invocation of the sum method to find the total balance of all accounts at the branch? a.Arrays.sum(branchAccounts) b.BankAccount.sum(branchAccounts) c.Measurable.sum(branchAccounts) d.branchAccounts.sum()

c.Measurable.sum(branchAccounts)

Assume a class implements two interfaces, both of which define a default method with the same signature. Which statement is true about this conflict of inherited methods? a.The code compiles but generates an exception at run time due to the conflict. b.The code compiles and the implementation is chosen at run time. c.The class must override the method and provide its own implementation. d.There is no conflict because interfaces cannot provide method implementation.

c.The class must override the method and provide its own implementation.

Which of the following statements about interfaces is true? a.You cannot define a variable whose type is an interface. b.You can define an interface variable that refers to an object of any class in the same package. c.You can define an interface variable that refers to an object only if the object belongs to a class that implements the interface. d.You can instantiate an object from an interface class.

c.You can define an interface variable that refers to an object only if the object belongs to a class that implements the interface.

Consider the following code snippet: myImage.add(new Rectangle(10,10,10,10)); This code is an example of using ____. a.an abstract class. b.an anonymous class. c.an anonymous object. d.an abstract object.

c.an anonymous object.

In Java, a reference variable is ________ because it can reference objects of types different from its own, as long as those types are related to its type through inheritance. a.dynamic b.public c.polymorphic d.static

c.polymorphic

The "has a" relationship is sometimes called a(n) ________ because one object is part of a greater whole. a.mutual relationship b.enterprise c.whole-part relationship d.possession

c.whole-part relationship

Which of the following is true about a default method in an interface declaration a. A default method is a static method that does not have an implicit parameter b. A default method does not provide an implementation. c. A class that implements the interface cannot override the default behavior. d.A class that implements the interface can inherit the default behavior.

d.A class that implements the interface can inherit the default behavior.

Which of the following statements about abstract methods is true? a.An abstract method has only a name and a return type, but no parameters or code in its body. b.An abstract method has a name, a return type, and code in its body, but has no parameters. c.An abstract method has parameters, a return type, and code in its body, but has no defined name. d.An abstract method has a name, parameters, and a return type, but no code in the body of the method.

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

During the implementation phase, which of the following statements is true? a.Class instance variables are available from the CRC cards. b.Class instance variables are available from the javadocs created during the design phase. c.You must determine the class instance variables during implementation phase. d.Class instance variables can be determined from the UML diagrams.

d.Class instance variables can be determined from the UML diagrams.

A class (ClassOne) is considered to have a dependency on another class (ClassTwo) under which of the following conditions? a.Each class uses objects of the other. b.The public interfaces of both classes are cohesive. c.ClassTwo uses objects of ClassOne. d.ClassOne uses objects of ClassTwo.

d.ClassOne uses objects of ClassTwo.

Mutator methods exhibit which of the following types of side effect? a.Modification of parameter variable. b.Production of printed output. c.Acceptance of text input. d.Modification of private instance variables.

d.Modification of private instance variables.

You are designing a software solution for an automobile rental company. A customer may rent only a single auto at a given time. You have decided that the following classes are needed: Auto, Customer, Address, Rental Contract. Which of these should be represented as aggregation? a.Rental Contract class aggregates Address class b.Rental Contract class does not aggregate any of the other classes. c.Rental Contract class aggregates Customer and Address classes. d.Rental Contract class aggregates Customer, Address, and Auto classes.

d.Rental Contract class aggregates Customer, Address, and Auto classes.

Which is an example of a class that needs to keep track of a total, i.e., a quantity that can go up and down? a.The Scanner class. b.The Shape class. c.The string class. d.The BankAccount class.

d.The BankAccount class.

Using the given definition of the Measurable interface: public interface Measurable { double getMeasure(); } Consider the following code snippet, assuming that BankAccount has a getBalance method and implements the Measurable interface by providing an implementation for the getMeasure method: Measurable m = new BankAccount(); System.out.println(m.getBalance()); Which of the following statements is true? a.The code does not compile because you cannot assign a BankAccount object to a variable of type Measurable. b.The code executes, displaying the balance of the bank account. c.The code compiles but generates an exception at run time because a Measurable object reference does not have a getBalance method. d.The code does not compile because a variable of type Measurable does not have a getBalance method.

d.The code does not compile because a variable of type Measurable does not have a getBalance method.

To use an interface, a class header should include which of the following? a.The keyword extends and the name of the interface b.The keyword extends and the name of an abstract method in the interface c.The keyword implements and the name of an abstract method in the interface d.The keyword implements and the name of the interface

d.The keyword implements and the name of the interface

A static field is created by placing the keyword static ________. a.after the access specifier and the field's data type b.in brackets, before the field's data type c.after the field name d.after the access specifier and before the field's data type

d.after the access specifier and before the field's data type

When a method is declared with the ________ modifier, it cannot be overridden in a subclass. a.Super b.void c.public d.final

d.final

How would you create the class PackageSample in a package named bigjava.chapter8? a.public package bigjava.chapter8.PackageSample {} b.public class bigjava.chapter8.PackageSample {} c.public class PackageSample : package bigjava.chapter8 {} d.package bigjava.chapter8; public class PackageSample {}

d.package bigjava.chapter8; public class PackageSample {}

Which container is used to group multiple user-interface components together? a.text area b.rectangle c.table d.panel

d.panel

When a reference variable is passed as an argument to a method ________. a.a copy of the variable's value is passed into the method's parameter b.the program terminates c.the method becomes a static method d.the method has access to the object that the variable references

d.the method has access to the object that the variable references

Which of the following code snippets denotes that the Kitchen class aggregates the Dish class? public class Dish { private Kitchen myKitchen; } public class Kitchen extends Dish public class Dish extends Kitchen public class Kitchen { private Dish dish; }

public class Kitchen { private Dish dish; }

Suppose that the invoice-printing application from section 12.3 needs to be enhanced by making it possible for class InvoicePrinter to store several invoices to be printed. Select the code segment that best illustrates reuse of the existing Invoice class for this purpose. public class InvoicePrinter ___________________________ { ArrayList<Invoice> invoices; . . . } extends Invoice { . . . } { Invoice invoice1; Invoice invoice2; . . . } implements Invoice { . . . }

{ ArrayList<Invoice> invoices; . . . }

Which of the following questions should you ask yourself in order to determine if you have named your class properly? a.Does the class name contain eight or fewer characters? b.Is the class name a verb? c.Can I describe an object of the class? d.Does the class name describe the tasks that this class will accomplish?

c.Can I describe an object of the class?

Which of the following is not true about static methods? a.It is not necessary for an instance of the class to be created to execute a static method. b.They are called from an instance of the class. c.They are often used to create utility classes that perform operations on data but have no need to collect and store data. d.They are called by placing the keyword static after the access specifier in the method header.

b. They are called from an instance of the class.

If a method in a subclass has the same signature as a method in the superclass, the subclass method ________ the superclass method. a.overrides b.implements c.inherits d.overloads

a.overrides

What mechanism is used by a class that is designed to collect and store a growing set of values? a.A string. b.Auto-boxing. c.a local variable d. an array list or array

d. an array list or array

Which of the following can be used to record the behavior of classes? a.Javadoc comments b.Nouns and verbs in the problem description c.Polymorphism d.UML notation

a.Javadoc comments

When a field is declared static there will be ________. a. only one copy of the field in memory b. two reference copies of the field for each method in the class c. a copy of the field for each method in the class d. a copy of the field in each class object

A) only one copy of the field in memory

A deep copy of an object ________. a.is an operation that copies an aggregate object and all the objects that it references b.is always a private method c.is an assignment of that object to another object d.is a bogus term and means nothing

a. is an operation that copies an aggregate object and all the objects that it references

____ is often described as the is-a relationship. a.Inheritance b.Aggregation c.Polymorphism d.Dependency

a.Inheritance

A(n) ________ method is a method that appears in a superclass but expects to be overridden in a subclass. a.overloaded b.abstract c.protected d.static

b.abstract

Why is it generally considered good practice to minimize coupling between classes? a.Low coupling increases the operational efficiency of a program. b.High coupling implies less interface cohesion. c.High coupling increases program maintenance and hinders code reuse. d.Low coupling decreases the probability of code redundancy.

c.High coupling increases program maintenance and hinders code reuse.

A new method, getMonthName, to get the name of the Date's month ("January", February", etc.) is to be added to the class Date. How will the instance variables need to be changed to handle this new method? a.The type of the month instance variable will need to be changed to String. b.A new String variable called monthName will need to be added to the class. c.A new class called MonthNameAndNumber will need to be created to store both the name and number of the month and the type of the instance variable month will need to be changed to MonthNameAndNumber. d.No change is needed.

d.No change is needed.

An object's ________ is simply the data that is stored in the object's fields at any given moment. a.State b.record c.value d.assessment

a.State

You cannot use the == operator to compare the contents of ________. a.Boolean values b.integers c.objects d.strings

c.objects

In Java, which of the following mechanisms describe the copying of an object reference into a parameter variable? a.Call-by-reference . b.Call-by-object. c.Call-by-precondition. d.Call-by-value.

d.Call-by-value.

A/an ____ class defined in a method signals to the reader of your program that the class is not interesting beyond the scope of the method. a.protected b.interface c.abstract d.inner

d.inner

The only limitation that static methods have is a.they can only be called from static members of the class b.they cannot refer to nonstatic members of the class c.they must be declared outside of the class d.they can refer only to nonstatic members of the class

b.they cannot refer to nonstatic members of the class

A UML class diagram would be most useful in visually illustrating which of the following? a.The cohesiveness of a class's interface. b.The amount of complexity of a class's interface. c.Dependencies between classes. d.Relationships between classes and their interfaces.

c.Dependencies between classes.


Conjuntos de estudio relacionados

Chapter 18 - Cardiovascular System - Blood

View Set

APES Chapter 1; What is an Environmentally Sustainable Society?

View Set

Unanticipated Problems and Reporting Requirements in Social and Behavioral Research

View Set

Chapter 7: Portable Fire Extinguishers

View Set

Two-Variable Linear Inequalities

View Set

450. David Goggins # Kids Explain What Is Love

View Set