Professional Documents
Culture Documents
Test Your Understanding - Constructor - Attempt Review
Test Your Understanding - Constructor - Attempt Review
Dashboard / Programming using Java / Hands On - Classes and Objects, Packages / Test Your understanding - Constructor
this.studentId = studentId; this.name = name;
this(studentId,name);
this.grade = grade;
}
[this(studentId,name);]
[this.grade = grade;]
}
Question VIRAG NIMESHKUMAR DOSA…
Observe the below code.
2
Correct
public class Student {
Mark 1.00 out of
1.00 private int id;
//Constructor 1
public Student() {
id=0;
//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.
//Constructor 1
public Student() {
id=0;
//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]
} Default constructor
public Student( ) {
} No-argument Constructor
}
} → Parameterized Constructor
Question Observe the code below. VIRAG NIMESHKUMAR DOSA…
4 public class Student {
Correct
int studentId;
Mark 1.00 out of
1.00
String name;
char grade;
this.name=name;
calculateGrade(mark);
if(mark>90)
grade='A';
else
grade='B';
Select one:
Compilation error because cannot call methods from constructor
Compilation error because of the parameter – mark - in constructor. It should be grade instead of mark.
Compiles successfully
Identify the valid option which is used to invoke the no argument constructor, Product(), at Line 1.
Select one:
super();
Product();
Product
this();