Why "Name" only work in the Constructor of "Student"? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 6

Why "Name" only work in the Constructor of "Student"?

Though the Name is protected, and it can be accessed within the Student constructor, why compiler shows an error while accessing Name from outside the Student constructor? Code below: https://code.sololearn.com/cOePnfDbeRHG/?ref=app

3rd Jan 2019, 3:42 PM
Muntaha Islam
Muntaha Islam - avatar
8 Réponses
+ 6
I was able to figure out the problem You didn't need to declare the Name field value since the constructor already handles that. Also you didn't call the speak method after instantiating. It would have worked if the console.writeline was on the constructor, but it was on a different method. I hope this. helps. Regards... https://code.sololearn.com/ckDAF163rlCo/?ref=app
4th Jan 2019, 2:06 AM
africana
africana - avatar
+ 4
You are welcome.
4th Jan 2019, 6:13 AM
africana
africana - avatar
+ 3
Care to share your code?
3rd Jan 2019, 4:24 PM
HonFu
HonFu - avatar
+ 3
Sure. Sorry for not adding it before. https://code.sololearn.com/cOePnfDbeRHG/?ref=app
3rd Jan 2019, 4:56 PM
Muntaha Islam
Muntaha Islam - avatar
+ 3
Unfortunately I can't solve this myself, but I hope we increased the probability of an incoming good answer now. :)
3rd Jan 2019, 4:59 PM
HonFu
HonFu - avatar
+ 2
Thanks. This helps a lot.
4th Jan 2019, 4:56 AM
Muntaha Islam
Muntaha Islam - avatar
+ 1
No problem. Thank you very much!
3rd Jan 2019, 5:01 PM
Muntaha Islam
Muntaha Islam - avatar
- 2
Hello
4th Jan 2019, 5:07 AM
‎عبدالرحمن بن احمد بن علي الزوبعي الشمري
‎عبدالرحمن بن احمد بن علي الزوبعي الشمري - avatar