Accenture Java Programming Practice Question
Observe the below code. public class Student { private int id; private String name; private char grade; //Constructor 1 public Student() { id=0; name= " "; } //Constructor 2 public Student(int id, String name) { this.id=id; this.name=name; } } Choose the constructor that is invoked, when an object is created as shown below. new Student(); Constructor 1 new Student(54, "John"); Constructor 2Answer options
Correct answer: public class Student { private int id; private String name; private char grade; //Constructor 1 public Student() { id=0; name= " "; } //Constructor 2 public Student(int id, String name) { this.id=id; this.name=name; } } Choose the constructor that is invoked, when an object is created as shown below. new Student(); Constructor 1 new Student(54, "John"); Constructor 2
Explanation
Correct answer: public class Student { private int id; private String name; private char grade; //Constructor 1 public Student() { id=0; name= " "; } //Constructor 2 public Student(int id, String name) { this.id=id; this.name=name; } } Choose the constructor that is invoked, when an object is created as shown below. new Student(); Constructor 1 new Student(54, "John"); Constructor 2.