Variable 'y' it's private so you can't access it directly from you subclass.
But you can organize the access to this variable creating public methods.
So when are you calling:
subclass.show ( 23 , 45 );
you are not accessing directly to 'y' attribute of 'A' class but only to a public method defined in it where you are using 'y'. You can do it because it's a method in 'A' class.
Trying to explain better:
Private modifier let your attribute in this case be not accesible from a subclass. So you can"t do this:
B b = new B();
b.y = 10;
Because you don't have direct access to this attribute.
So now you can define how subclass can access this private attribute with a public method. The best example will be a getter or setter: (this methods have to be defined in your superclass)
Public int getY(){
Return this.y;
}
Public void setY(int y){
This.y = y;
}
Now you can access to private attribute 'y' but you need to call this public method so now you can do:
B b = new B();
b.setY(10);
And you will change the value of 'y'.
Now, according to yuor code, you didn't made any setter or getter but you defined a method call 'show(int,int)' where you are changing the value of 'y'.
And this is working likely as setter methods.
So you can access directly this method like:
B b = new B();
b.show(5,10);
Because it's a public method. And inside of this method you are doing operationts on a private attribute.
So, finally, the private attribute 'y' belongs to 'A' superclass and can't be access directly by any subclass but you can manage operations defining public method in superclasw where you specific how other classes can access superclass private attribute.
I have this doubt because since y is a private variable then how can y belong to object subclass ?
'y' doesn't belong to subclass. As i said before you can access 'private' attributes only using public methods defined in superclass. So if i want to change value or show 'y' i can do it only if there is public methods in superclass that change or show 'y' value.
void show (int o ,int e )
{
x=o ; // I mean to say ,
int y ; // Is this implicitly declared above ?
y=e ;
System.out.println(" x = " + x);
System.out.println(" y = " + y);
}
Here you don't need to declare 'int y;' because this method is defined in superclass and so you have direct access to 'y'.
If you need more please comment.