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?
A) Student s1 = new Student( ) ;
B) s1 = new Student( ) ;
C) Student s1 = new Student("Jane Doe", "Computer Science", 3.333, 33) ;
D) new Student s1 = ("Jane Doe", "Computer Science", 3.333, 33) ;
E) new Student(s1) ;
Correct Answer:
Verified
Q7: In order to preserve encapsulation of an
Q8: Consider a Rational class designed to represent
Q9: An example of passing message to a
Q13: To define a class that will represent
Q14: Consider a method defined with the header:
Q15: For the questions below, use the following
Q16: Instance data for a Java class
A) are
Q17: For the questions below, use the following
Q28: If a method does not have a
Q37: Consider a sequence of method invocations as
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents