1.

Which among the following is correct?(a) class student{}s1,s2; s1.student()=s2.student();(b) class student{}s1; class topper{}t1; s1=t1;(c) class student{}s1,s2; s1=s2;(d) class student{}s1; class topper{}t1; s1.student()=s2.topper();The question was asked in examination.The query is from Objects in section OOPs Concept & Features of Object Oriented Programming

Answer»

The correct CHOICE is (c) class student{}S1,S2; s1=s2;

The best explanation: Only if the objects are of same class then their data can be copied from to another using assignment OPERATOR. This actually comes under operator OVERLOADING. Class constructors can’t be assigned any explicit value as in option class student{}s1; class topper{}t1; s1=t1; and class student{}s1; class topper{}t1; s1.student()=s2.topper();.



Discussion

No Comment Found

Related InterviewSolutions