Exam 4: Writing Classes

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Write the constructor, which is passed the player's name and position.

(Essay)
4.8/5
(37)

What happens if you declare a class constructor to have a void return type?

(Multiple Choice)
4.8/5
(38)

Write the constructor for this class.

(Essay)
4.8/5
(36)

For the questions below, use the following class definition. 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( ) { DecimalFormat df = new DecimalFormat("xxxx"); // xxxx needs to be replaced return name + "\n" + major + "\n" + df.format(gpa) + "\n" + hours } } -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)
5.0/5
(38)

Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal?

(Multiple Choice)
4.7/5
(37)

Write a statement to instantiate a cube with a length of 3, width of 3, and height of 3.

(Short Answer)
4.8/5
(38)

The following method header definition will result in a syntax error: public void aMethod( );

(True/False)
4.8/5
(40)

For the questions below, use the following class definition. 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( ) { DecimalFormat df = new DecimalFormat("xxxx"); // xxxx needs to be replaced return name + "\n" + major + "\n" + df.format(gpa) + "\n" + hours } } -Which of the following could be used to instantiate a new Student s1?

(Multiple Choice)
4.9/5
(41)

The expressions that are passed to a method in an invocation are called

(Multiple Choice)
4.9/5
(40)

Listener objects "wait" for an event to occur.

(True/False)
4.8/5
(30)

Java methods can return only primitive types (int, double, float, char, boolean, etc).

(True/False)
4.8/5
(41)

Which of the following Applet methods is called automatically when the applet is first loaded?

(Multiple Choice)
4.8/5
(38)

Consider the "Push Me!" program described in section 4.7. As given the push counter starts at zero and is incremented each time the "Push Me!" button is pressed. Let's say that you want to add a class called ResetListener that resets the count to zero. Write the ResetListener class.

(Essay)
4.8/5
(36)

A class' constructor usually defines

(Multiple Choice)
4.8/5
(34)

Write a statement to output the volume of the blue box.

(Essay)
4.9/5
(35)

Every class definition must include a constructor.

(True/False)
4.8/5
(35)
Showing 41 - 56 of 56
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)