Why do protected attributes in a Java class can be accessed by the other classes of the same package ?
I thought it was only accessible through inheritance.
A.java
package abc;
class A {
protected int attr1;
}
B.java
package abc;
class B {
B() {
A obj = new A();
obj.attr1 = 2;
}
public static void main(String[] args) {
B obj2 = new B();
}
}