Which among following is correct for initializing the class below? [code] class student{ int marks; int cgpa; public: student(int i, int

Mỹ An

New member
Which among following is correct for initializing the class below?
Code:
class student{
int marks;
int cgpa;
public: student(int i, int  j){
marks=I;
cgpa=j
}
};
A. student s[3]={ s(394, 9); s(394, 9); s(394,9); };
B. student s[2]={ s(394,9), s(222,5) };
C. student s[2]={ s1(392,9), s2(222,5) };
D. student s[2]={ s[392,9], s2[222,5] };
 
Answer: b
Explanation: It is the way we can initialize the data members for an object array using parameterized constructor. We can do this to pass our own intended values to initialize the object array data.
 

Tìm kiếm

Back
Top