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
Given the method defined here, which of the following method calls is legal? public void doublefoo(double x)
(Multiple Choice)
4.8/5
(32)
Explain why it would be a poor decision to make instance data public instead of private. Give an example of why this could result in a problem.
(Essay)
4.7/5
(33)
Assume method0 calls method1 and method2, method1 calls method3 which calls method4 and method5. Explain the chain of method calls (what order methods are called and from which method).
(Essay)
4.8/5
(33)
Accessors and mutators provide mechanisms for controlled access to a well-encapsulated class.
(True/False)
4.7/5
(31)
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 the statement to instantiate an Box object, blueBox, with a length of 6, width of 4, and height of 2.
(Short Answer)
4.9/5
(28)
The interface of a class is based on those data instances and methods that are declared public.
(True/False)
4.9/5
(39)
A variable whose scope is restricted to the method where it was declared is known as a(n)
(Multiple Choice)
4.9/5
(39)
What happens if you declare a class constructor to have a void return type?
(Multiple Choice)
4.9/5
(43)
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 could be used to instantiate a new Student s1?
(Multiple Choice)
4.7/5
(35)
Because an Image cannot directly be added to a container, it must be displayed using an ImageView object.
(True/False)
4.9/5
(39)
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 instantiate a cube with a length of 3, width of 3, and height of 3.
(Short Answer)
4.9/5
(36)
While multiple objects of the same class can exist, in a given program there can only be one version of each class.
(True/False)
4.8/5
(37)
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: Another method that might be desired is one that updates the student's number of credit hours. This method will receive a number of credit hours and add these to the student's current hours. Which of the following methods would accomplish this?
(Multiple Choice)
4.8/5
(37)
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: Add a constructor to class Box for a cube which has only 1 parameter, side.
(Essay)
4.8/5
(41)
Class Definition Ch 04-3
Consider a class called Building. This class consists of a number of floors (numberOfFloors) for the building, a current floor for the elevator (current), a requested floor of a person waiting for the elevator (requestedFloor), and methods for constructing the building object, for moving the elevator one floor up, for moving the elevator one floor down, for requesting the elevator and for starting the elevator going. Assume that requestedFloor will be set to 0 if there are currently no requests being made (or the last request has already been fulfilled).
-Refer to Class Definition Ch 04-3: Write the constructor for this class.
(Essay)
4.9/5
(41)
Regarding the software failure described at the Denver International Airport in the text, it is critical to factor in errors and inefficiencies that alway occur in a complex system.
(True/False)
4.9/5
(35)
Showing 21 - 40 of 53
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)