Say I have a class declared with default access. If a member in the class is declared protected
or public
, is it equivalent to the member being declared with default
access?
For example:
In CarA.java:
class CarA { //class declared with default access
public int odometer;
protected void forward(int distance){...
}
protected static void tally(){...
}
}
In CarB.java:
class CarB { //class declared with default access
int odometer;
void forward(int distance){...
}
static void tally(){...
}
}
Are CarA
and CarB
equivalent?
My reasoning is that since the class is not declared as public
, the class is not accessible outside of its package, so its members should not be accessible outside of its package as well. Could someone confirm my thinking is correct?