Jack McLaren wrote:
Why code at //1 is valid ? JVM will provide constructor for Parent class, that is not package private ? if not then what is access modifier of that constructor ?
It is
protected. So any class in the same package AND any child of that class (or child of a child and so on...) might access it.
Jack McLaren wrote:
Why code at //2 is invalid although parentMethod() is protected but Child extends Parent class so it should work ?
Because my above statement only applies to inheritance (extending a class) and seeing a class as a whole (and that includes any protected constructors), but not accessing other class' fields or methods.