+ 2

can we initailize the variables inside the class ?eg class{public: int a=10;}

2nd Nov 2016, 10:43 AM
sadiya zainab
sadiya zainab - avatar
6 Answers
+ 1
your answer is wrong
2nd Nov 2016, 10:55 AM
sadiya zainab
sadiya zainab - avatar
+ 1
error will come if we do that
2nd Nov 2016, 10:57 AM
sadiya zainab
sadiya zainab - avatar
+ 1
no you can't. You can use constructor to initialise you variable
2nd Nov 2016, 6:43 PM
kamal joshi
kamal joshi - avatar
+ 1
Sorry. I am wrong. I am used to other languages. As kamal said you can use a constructor to initialize variable.
2nd Nov 2016, 8:07 PM
nedas
nedas - avatar
0
Yes you can. You can also set the private if you need that.
2nd Nov 2016, 10:52 AM
nedas
nedas - avatar
0
yes we can initialize the variable inside class using const variable or class variable
14th Nov 2016, 4:06 PM
Junaid Ali
Junaid Ali - avatar