CMIS 234 Exam 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What class or classes is a method that is declared protected available to? a. All classes in all packages b. All classes in the same package c. The current class d. All classes in the same package and to subclasses

d. All classes in the same package and to subclasses

When using an IDE, what must you do to use a class that's stored in a library? a. Nothing. Classes in libraries are automatically available. b. Code an import statement for the class. c. Add the library to your project. d. Both b and c.

d. Both b and c

You can use ____________ within a javadoc comment to apply formatting to the text when it's displayed.

HTML tags

Which of the following is a valid javadoc comment? a. /** Calculates the balance due **/ b. // Calculates the balance due // c. /** Calculates the balance due ***/ d. /*** Calculates the balance due **/

d. /*** Calculates the balance due **/

What does the following code display? public class GradeCurveApp { public static void main(String[] args) { int grade = 95; GradeCurve curve = new GradeCurve(); curve.lowerGrade(grade); System.out.println(grade); } } public class GradeCurve { public void lowerGrade(int g) { g -= 5; } } a. 95 b. 90 c. 0 d. -5

a. 95

Which of the following is NOT an advantage of using a three-tiered architecture for your applications? a. It makes it easier to document the tasks performed by an application. b. It simplifies program maintenance. c. It allows more than one programmer to work on the same application at the same time. d. It allows more than one application to use the same classes.

a. It makes it easier to document the tasks performed by an application.

Which of the following is NOT a reason to create a package? a. To prevent other developers from using the class b. To make it easy to reuse classes c. To make finding classes easier d. To group related classes

a. To prevent other developers from using the class

Explicit casting is always required to cast... a. a superclass object to a subclass object b. a subclass object to a superclass object c. both a and b d. neither a nor b

a. a superclass object to a subclass object

Which of the following is true about a method that has this declaration? public Employee getDepartmentManager(){...} a. it returns an object of the Employee class b. it uses an Employee object as a parameter c. it's located in the Employee class d. it's only accessible within its class

a. it returns an object of the Employee class

invoice InvoiceApp.java murach business Invoice.java LineItem.java Product.java database ProductDB.java presentation Validator.java If the directory structure is for an application that uses packages, what statement must the first statement of the ProductDB class be? a. package murach.database b. package invoice.murach.database c. import invoice.murach.database d. import murach.database

a. package murach.database

Which of the following methods can always be called from a Product object? a. toString() b. next() c. equalsIgnoreCase() d. hasString()

a. toString()

What does the following code display? public class RentalApp { public static void main(String[] args) { Rental r = new Rental(); r.setNumOfPersons(5); r.addPerson(r); System.out.println(r.getNumOfPersons()); } } public class Rental { private int numOfPersons; public int getNumOfPersons() { return numOfPersons; } public void setNumOfPersons(int numOfPersons) { this.numOfPersons = numOfPersons; } public void addPerson(Rental rental) { rental.numOfPersons++; } } a. 5 b. 6 c. 1 d. 0

b. 6

Which of the following is true? a. A method can operate directly on the value of a primitive type that's passed to it and change that value b. A method can operate directly on the data in a reference type that's passed to it and change that data c. Both a and b d. Neither a nor b

b. A method can operate directly on the data in a reference type that's passed to it and change that data

If a method accepts an Object object, what other types of objects can it accept? a. Only objects from classes that explicitly extend the Object class b. All objects c. Only objects from the Java API classes d. None

b. All objects

What happens when this statement is executed? Automobile car = new Automobile(1); a. An object of the Automobile class is declared, but not created. b. An object of the Automobile class is created. c. The default constructor in the Automobile class is called. d. A constructor that accepts a string in the Automobile class is called.

b. An object of the Automobile class is created.

Where must you code the javadoc comment for a method? a. Anywhere within the method b. Immediately before the method c. Before any statements in the method d. After any statements in the method

b. Immediately before the method

Which of the following is a benefit of using javadoc comments? a. They allow other programmers to view the source code for your class. b. They make it easy for other programmers to learn about your class. c. They show other programmers how to code a class. d. They make your classes easier to debug.

b. They make it easy for other programmers to learn about your class.

If the instance variables of the Employee class are declared as follows, which of the following statements is most likely to be in the constructor of this class? private String name; private Address address; private long employeeNumber; a. employeeNumber = "11233444"; b. address = new Address(); c. address = " "; d. address = 0;

b. address = new Address();

To include a class in a package, you... a. code the name of the package in the class declaration b. code a package statement as the first statement in the class file c. code an import statement as the first statement of the class

b. code a package statement as the first statement in the class file

Which of the following method declarations overrides this method? double calculateMilesPerGallon(double speed){...} a. double calculateMilesPerGallon(double speed, int r){...} b. double calculateMilesPerGallon(double s){...} c. double calculateMilesPerGallon(int speed){...} d. double calculate(double speed){...}

b. double calculateMilesPerGallon(double s){...}

The attributes of an object are often coded as... a. static variables b. instance variables c. methods d. static methods

b. instance variables

When a subclass that is NOT declared as abstract inherits an abstract class... a. it must override all of the methods in the abstract class b. it must override all of the abstract methods in the abstract class c. it must override all of the final methods in the abstract class d. it can't override any of the methods in the abstract class

b. it must override all of the abstract methods in the abstract class

If the duesOwed instance variable in the code that follows is set in the setDuesOwed() method, which of the following is NOT true about the setDuesOwed() method? private String name; //instance variable private double duesOwed; //instance variable public Member(String s) { name = s; setDuesOwed(name); } a. it operates on an object b. it's a static method c. it doesn't return a value d. it accepts a String argument

b. it's a static method

invoice InvoiceApp.java murach business Invoice.java LineItem.java Product.java database ProductDB.java presentation Validator.java If the directory structure is for an Invoice application that uses packages, what is the name of the package that contains the Invoice.java class? a. business b. murach.business c. business.murach d. invoice.murach.business

b. murach.business

If the constructor that follows is in the Employee class, what other form of constructor, if any, is implicitly provided? public Employee(String name, int salary){...} a. Employee(){...} b. none c. Employee(String name){...}

b. none

To check if an object is created from the specified class, you can use... a. the createdFrom keyword b. the instanceof keyword c. the isTypeOf() method d. the equals() method

b. the instanceof keyword

What is the difference between these two constructors? public Transaction(){...} public Transaction(int x, int y){...} a. they initialize different variables b. they have different signatures c. they belong to two different classes d. they create different object types

b. they have different signatures

What is the name of the class that contains this code? private Clock clock; private Alarm alarm; public AlarmClock(Date time){...} a. can't determine the class name from the information given b. Alarm c. AlarmClock d. Clock

c. AlarmClock

What class or classes is a variable available to if it is declared without an access modifier? a. All classes in the same package and to subclasses b. All classes in all packages c. All classes in the same package d. Only the current class

c. All classes in the same package

If the Point class doesn't override the equals() method in the Object class, what will the following code do? Point pointOne = new Point(3, 4); Point pointTwo = new Point(3, 4); System.out.println(pointOne.equals(pointTwo)); a. Cause a compile-time error since the equals() method doesn't exist in the Point class b. Print "true" to the console c. Print "false" to the console d. Cause a compile-time error since the equals() method can't accept a Point object

c. Print "false" to the console

If name is a String instance variable, average is a double instance variable, and numOfStudents is a static int variable, why won't the following code from a class compile? public Student(String s) { name = s; average = getAverage(name); numOfStudents++; } public double getAverage(String x) { numOfStudents++; double ave = StudentDB.getAverage(x); return ave; } public static void setAverage(double g) { average = g; } a. The getAverage() method can't call a static method in the StudentDB class. b. The constructor can't increment the numOfStudents variable. c. The setAverage() method can't access the average instance variable. d. The getAverage() method can't increment the numOfStudents variable.

c. The setAverage() method can't access the average instance variable.

In which of the following situations would it make most sense to code a static method rather than a regular method in a class that defines a bank account? a. a method that calculates the number of deposits made in an account b. a method that posts a transaction c. a method that changes the annual interest rate for all bank accounts d. a method that returns the bank account balance

c. a method that changes the annual interest rate for all bank accounts

What keyword do you use in a class declaration to create a subclass? a. inherits b. overloads c. extends d. overrides

c. extends

To compare the instance variables of two objects, you can... a. use the equals() method in the Object class b. override the clone() method of the Object class c. override the equals() method of the Object class d. use the clone() method in the Object class

c. override the equals() method of the Object class

Which method is an example of overloading the method that follows? public int parseNumber(String numberString){...} a. public int parseNumber(String num){...} b. public double parseNumber(String numberString){...} c. public int parseNumber(String numberString, String entry){...}

c. public int parseNumber(String numberString, String entry){...}

The values held by the attributes of an object describe the object's... a. class b. identity c. state d. operation

c. state

Which of the following is NOT true about generated Java documentation? a. It lists all public methods of the class. b. It lets you view classes by package. c. It indicates the package that a class belongs to. d. It includes the code that implements each documented method.

d. It includes the code that implements each documented method

Which of the following can you NOT code in a subclass? a. a method with the same signature as a method in the superclass b. a call to a constructor of the superclass c. a method that's not defined by the superclass d. a call to a private method of the superclass

d. a call to a private method of the superclass

A static initialization block... a. is used to initialize a static variable that can't be initialized in the declaration b. is executed when a static method of the class is called c. is executed when an instance of the class is created d. all of the above e. a and b only

d. all of the above

You can use the final keyword... a. to prevent a class from being inherited b. to prevent a method from being overridden c. to prevent a method from assigning a new value to a parameter d. all of the above e. none of the above

d. all of the above

When you call the equals() method in the String class without knowing how it's coded, you're taking advantage of what object-oriented concept? a. instantiation b. inheritance c. modeling d. encapsulation

d. encapsulation

In what type of file is javadoc documentation stored? a. class file b. java file c. txt file d. html file

d. html file

Which of these statements is NOT true about the method that follows? public void deposit(Date date, double amt) { this.balance += amt; this.printDeposit(accountNum, date, amt); } a. accountNum is declared outside of the method b. printDeposit is located in the same class c. balance is an instance variable d. printDeposit is a static method

d. printDeposit is a static method

You must use the this keyword... a. to refer to any method that's called within a user-defined class b. to pass an object by reference to a method c. to pass a primitive type by value to a method d. to refer to an instance variable from a method when it has the same name as a method parameter

d. to refer to an instance variable from a method when it has the same name as a method parameter

A package corresponds with a ___________ that has the same name as the package.

directory

To include special entries in javadoc documentation, you use ____________.

javadoc tags

A __________ is typically stored in a JAR file and contains one or more packages that you want to make available to other projects.

library

To view javadoc documentation, you use a ________________.

web browser


Set pelajaran terkait

Intro to Drugs and Behavior Chpater 11

View Set

Dr. Draper PSY 4300 ALL Chapters

View Set

Chapter 7: Assessing and Securing Your Credit

View Set

PrepU: Chapter 69: Management of Patients With Neurologic Infections, Autoimmune Disorders, and Neuropathies

View Set

MaryANN HoGAN MedSurg. Nursing Chapter 25 Principles

View Set

Impact of European Explorers on Native Americans

View Set

Generalized Anxiety Disorder (Sherpath)

View Set