Question : Whether b.x =1 statement in class A and class B is okay or not ?

public class A
{
int x;
static void SetX(B b)
{
b.x = 1; }
}
public class B : A
{
static void SetX(B b)
{
b.x = 1;
}
}

Answer :
b.x = 1 in Class A is fine.
b.x = 1 in Class B gives compilation error

Help :
As x is private field in Class A hence accessible within Class A
As x is private field in Class A and hence not accessible in Class B

No comments:

Popular Posts