What is the difference between protected and private?

danijar picture danijar · Oct 8, 2012 · Viewed 92.1k times · Source

I don't understand the difference between protected and private members or methods, as I assumed both will hide the member or the function to access from outside the class.

What is the difference between the protected and the private keywords?

Answer

dsgriffin picture dsgriffin · Oct 8, 2012

private - only available to be accessed within the class that defines them.

protected - accessible in the class that defines them and in other classes which inherit from that class.