Inconsistent accessibility: base class 'A' is less accessible than class 'B'

Posted by Santosh.impossible under C# on 7/20/2011 | Points: 10 | Views : 7889 | Status : [Member] | Replies : 3
Hi WebGurus,

Can anyone please help to know what is the problem in the below mentioned code snippet

internal class A { }
public class B : A { }

When I am trying to build the solution I am getting the following error:

Error: Inconsistent accessibility: base class 'A' is less accessible than class 'B'

Thanks & Regards,
Santosh

santosh kumar patro


Responses

Posted by: Jpchoudhari on: 7/21/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

This is because your class A has internal Access Modifier and it will not be available outside assembly; So either remove public from class B or declare class A as public.

Note: A class has default modifiers as Internal.


Kind Regards,
Jay

Santosh.impossible, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santosh.impossible on: 7/21/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Jaydeep,

Thanks a lot for your reply. Please let me know whether my understanding regarding your feedback is in line with you.

Since Class B is public so it is accessible outside the assembly too but here Class B is acessing Class A which is having internal as the access modifier so it will contradict the rules . Hence when I am building the page the compiler is throwing the error.

Thanks & Regards,
Santosh

santosh kumar patro

Santosh.impossible, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jpchoudhari on: 7/21/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

yes, you got it right.

For More Information on Member access and Accessibility refer:
http://msdn.microsoft.com/en-us/library/aa691130(v=VS.71).aspx
http://msdn.microsoft.com/en-us/library/aa691126(v=VS.71).aspx

Kind Regards,
Jay

Santosh.impossible, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response