‹ Back to the paper
Question 10
1 mark
Computer ScienceISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024)MCQObjects
Choose the correct option.
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?- (a)StudentBanyan stud1 = new StudentBanyan("Kylin",5.6, 23);
- (b)StudentBanyan stud1 = new StudentBanyan("Kylin",23, 5.6);
- (c)StudentBanyan stud1 = new StudentBanyan(5.6, "Kylin",23);
- (d)StudentPine stud1 = new StudentPine(5.6, 23, "Kylin");
Answer
Answer
Correct 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.