Exam 4: Writing Classes
Exam 1: Introduction64 Questions
Exam 2: Data and Expressions67 Questions
Exam 3: Using Classes and Objects49 Questions
Exam 4: Writing Classes53 Questions
Exam 5: Conditionals and Loops38 Questions
Exam 6: More Conditionals and Loops35 Questions
Exam 7: Object-Oriented Design44 Questions
Exam 8: Arrays45 Questions
Exam 9: Inheritance49 Questions
Exam 10: Polymorphism40 Questions
Exam 11: Exceptions39 Questions
Exam 12: Recursion55 Questions
Exam 13: Collections60 Questions
Select questions type
Java methods can only return primitive types.
Free
(True/False)
4.8/5
(38)
Correct Answer:
False
Consider a Rational class designed to represent rational numbers as a pair of ints, along with methods reduce (to reduce the rational to simplest form), gcd (to find the greatest common divisor of two ints), as well as methods for addition, subtraction, multiplication, and division. Why should the reduce and gcd methods be declared to be private?
Free
(Multiple Choice)
4.8/5
(34)
Correct Answer:
B
Having multiple class methods of the same name where each method has a different number of or type of parameters is known as
Free
(Multiple Choice)
4.7/5
(35)
Correct Answer:
E
The software failure at the Denver International Airport's baggage handling system is a good example of
(Multiple Choice)
4.8/5
(32)
Class Definition Ch04-2
The following is from a class named BaseballPlayer. It contains the following data instances:
private String name;
private String position;
private int numAtBats;
private int numSingles;
private int numDoubles;
private int numTriples;
private int numHomeRuns;
private double battingAverage;
-Refer to Class Definition Ch 04-2: Write the constructor which is passed the player's name and position.
(Essay)
4.7/5
(37)
In order to preserve encapsulation of an object, we would do all of the following except for which one?
(Multiple Choice)
4.9/5
(29)
The following method header definition will result in a syntax error:
public void aMethod();
(True/False)
4.9/5
(39)
Given the method defined here, which of the following method calls is legal? public void foo(int a, int b)
(Multiple Choice)
4.9/5
(40)
Class Definition Ch 04-4
public class Box
{
double length;
double width;
double height;
Box(double l, double w, double h)
{
length = l;
width = w;
height = h;
}// Box( )
double volume()
{
return length * width * height;
}// end volume()
}// end class Box
-Refer to Class Definition Ch 04-4: Write a statement to output the volume of the blue box.
(Essay)
4.8/5
(28)
Formal parameters are those that appear in the method call and actual parameters are those that appear in the method header.
(True/False)
4.8/5
(39)
A constructor may contain a return statement so long as no value (or expression) is returned.
(True/False)
4.9/5
(28)
Class Definition Ch 04-1
import java.text.DecimalFormat;
public class Student
{
private String name;
private String major;
private double gpa;
private int hours;
public Student(String newName, String newMajor, double
newGPA, int newHours)
{
name = newName;
major = newMajor;
gpa = newGPA;
hours = newHours;
}
public String toString()
{
// xxxx needs to be replaced
DecimalFormat df = new DecimalFormat("xxxx"); return name + "\n" + major + "\n" + df.format(gpa)
+ "\n" + hours
}
}
-Refer to Class Definition Ch 04-1: Which of the following patterns should be used in place of "xxxx" when instantiating df so that the gpa to be output is in typical form (like 3.810)?
(Multiple Choice)
4.7/5
(32)
When reasoning about a car, we use such information as its make and model, year, color, cost (or worth), number of miles, gas mileage, insurance cost, and so forth. Consider a program that will attempt to determine how practical a car might be on a road trip. Which of these types of information might you use in your program as instance data? Provide a justification for your selection.
(Essay)
4.8/5
(39)
A GUI control sets up an event but it is the programmer who writes the code for the event handler which executes when an event occurs.
(True/False)
4.9/5
(37)
Consider a sequence of method invocations as follows: main calls m1, m1 calls m2, m2 calls m3, and then m2 calls m4, m3 calls m5. If m4 has just terminated, what method will resume execution?
(Multiple Choice)
4.9/5
(40)
To define a class that will represent a car, which of the following definition is most appropriate?
(Multiple Choice)
4.9/5
(39)
An object should be encapsulated in order to guard its data and methods from inappropriate access.
(True/False)
4.7/5
(40)
A method defined in a class can access the class's instance data without needing to pass them as parameters or declare them as local variables.
(True/False)
4.9/5
(40)
Showing 1 - 20 of 53
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)