Computer Science, asked by sarkarsid, 8 months ago

Drag and drop the code so that the constructor for Student class is overloaded correctly.
public class Student {
private int studentid;
private String name;
private float grade;
public Student(int studentld, String name) {
________________
}
public Student(int studentld, String name, float grade) {
________________
________________
}
}
fill the gaps from the below options
a)this(studentld name);
b)this.grade = grade;
c)this studentld = studentid; this.name = name;​

Answers

Answered by indraninaza
3

Answer:

1st blank : this stundentId = studentid;

this. name = name;

Explanation:

2nd blank = this(student Id, name) ;

3rd blank = this. grade= grade;

Answered by Jasleen0599
0

JAVA CODE

public class Student {

private int studentid;

private String name;

private float grade;

public Student(int studentld, String name) {

this studentld = studentid;

this.name = name;​

}

public Student(int studentld, String name, float grade) {

this(studentld name);

this.grade = grade;

}

}

  • In a method or function Object() the this keyword refers to the current object. This keyword is most frequently used to avoid misunderstanding between class attributes and parameters with the same name (because a class attribute is shadowed by a method or function Object() parameter).
  • The current class instance variable can be referred to using the this keyword. This keyword solves the ambiguity issue if there is any between the instance variables and parameters.

#SPJ2

Similar questions