Inconsistent Accessibility

by Erik Lane 9. May 2006 15:38

This is one of those errors that can drive you nuts while you dig down your class hierarchy and find the culprit.  You will typically create this error while not realizing it when you change the access modifier on a class that is being returned by a public method.  Why?  Because if you return a protected or private class from a public method the client of your public method cannot use the class that you just returned.

I know it makes sense but sometime you're coding a way and don't see it.  As a good programmer you know you need to keep your scope as narrow as you can; so you change something from public to protected or private and that's that.

After  few more minutes of coding you need to compile and then it hits.  This happened to me today and I couldn't remember where I made the change and had to dig for it.  Note to self:  If I make a change in accessibility, immediately try and compile.

Tags:

Comments

M.Al-Bakri
M.Al-Bakri on 10/23/2008 10:02:00 AM

I has this Error ,, but the Class that i am taking a Object from it not private or protected ,,
the variables are private ,,,!!
what should i do !!

Rakesh
Rakesh United States on 6/11/2009 2:53:42 PM

thanks, this information helped me

Comments are closed