Multiple Choice
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
}
}
-Assume that another method has been defined that will compute and return the student's class rank (Freshman, Sophomore, etc) . It is defined as: public String getClassRank( )
Given that s1 is a student, which of the following would properly be used to get s1's class rank?
A) s1 = getClassRank( ) ;
B) s1.toString( ) ;
C) s1.getHours( ) ;
D) s1.getClassRank( ) ;
E) getClassRank(s1) ;
Correct Answer:

Verified
Correct Answer:
Verified
Q2: Consider a Rational class designed to represent
Q3: Write a toString method that returns the
Q9: The behavior of an object is defined
Q11: An example of passing message to a
Q12: A constructor may contain a return statement
Q12: In order to preserve encapsulation of an
Q16: Consider a sequence of method invocations as
Q19: Formal parameters are those that appear in
Q25: Accessors and mutators provide mechanisms for controlled
Q51: The relationship between a class and an