What will be the output :
1. package package1;
2. class ParentClass ParentClass {
3. protected x=9;
4. }
1. package package2;
2. import package1;
3. class ChildClass extends ParentClass {
4. public static void main (
String [] args) {
5. ChildClass cc = new ChildClass();
6. System.out.print("child " + cc.x);
7. ParentClass pc = new ParentClass();
8. System.out.print(" parent " + pc.x);
9. }
10. }
My question is why line 8 is giving error. As child class has extended the parent class, so the child class can see what is there in the parent class so why cant the object of parent class use the X while child class object can use it.