+ 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
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
+ 4
You are welcome.
+ 3
Care to share your code?
+ 3
Sure. Sorry for not adding it before.
https://code.sololearn.com/cOePnfDbeRHG/?ref=app
+ 3
Unfortunately I can't solve this myself, but I hope we increased the probability of an incoming good answer now. :)
+ 2
Thanks. This helps a lot.
+ 1
No problem. Thank you very much!
- 2
Hello