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?
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
Q21: Having multiple class methods of the same
Q28: If a method does not have a
Q29: A class's constructor usually defines
A) how an
Q30: Visibility modifiers include
A) public, private
B) public, private,
Q31: Given the method defined here, which of
Q34: Given the method defined here, which of
Q35: An example of passing a message to
Q36: The expressions that are passed to a
Q37: Consider a sequence of method invocations as
Q38: Which of the following reserved words in
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