‹ Back to the paper
Software developers of Banayan High School have created a class to store the name, age and height…
Software developers of Banayan High School have created a class to store the name, age and height of students. If the class shown below compiles correctly, which of the following will be the correct statement to create an object and pass values as an argument?
class StudentBanyan
{
String name;
int age;
double height;
StudentBanyan(String n, int a, double h)
{
name = n;
age = a;
height = h;
}
//implementation not shown here
}Which one of the following is the correct statement of using a constructor?- aStudentBanyan stud1 = new StudentBanyan("Kylin",5.6, 23);
- bStudentBanyan stud1 = new StudentBanyan("Kylin",23, 5.6);
- cStudentBanyan stud1 = new StudentBanyan(5.6, "Kylin",23);
- dStudentPine stud1 = new StudentPine(5.6, 23, "Kylin");
Answer
Answer
AICorrect option: b
Answer: (b) StudentBanyan stud1 = new StudentBanyan("Kylin",23, 5.6);
The constructor's parameter order is (String n, int a, double h), so the arguments passed to new StudentBanyan(...) must be a String, then an int, then a double, in that order - name, age, then height.
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 10.