0

Why in this program "Protected" is used before we use "Public" ?

In mother class "enemy" ? https://code.sololearn.com/c27Jb1k9Vq22/?ref=app

18th Oct 2018, 3:51 PM
Abhishek kumar
Abhishek kumar - avatar
3 Antworten
+ 5
I don't know what was the purpose of the code, but I think Enemy is just a pattern for Ninja and Monster, so you shouldn't use it itself. If you've used public specifier, you could be able to use this property of Enemy, but protected makes it private in mother class and public in inheriting classes.
19th Oct 2018, 4:35 AM
Aleksander Szczepura
Aleksander Szczepura - avatar
+ 4
I corrected some errors, beacuse code wasn't working. Proteced means you cannot use AttackPower of class enemy (it will result in an error), but you can use this property in inheriting classes. https://code.sololearn.com/cIPigJgYNo4c/?ref=app
18th Oct 2018, 5:53 PM
Aleksander Szczepura
Aleksander Szczepura - avatar
0
thanks Olek ! But I want to know that why we should initialize the mother class "Enemy" with protected : specifier and why not with public : ? And why we get error when we write the code in which protected : specifier is specified after public : ( like I had done in my code ) ??
19th Oct 2018, 2:54 AM
Abhishek kumar
Abhishek kumar - avatar