Access Parent class Variables in child class

Is it possible to get the Parent class Variales in child class.? and if no why not.?

i came across a question in my Youtube channel Video.

Parent Class

[java]

class base
{
int x=10;
}

[/java]

Child Class

[java]

class child extends base
{
public static void main(String s[])
{
int x=20;
child obj=new child();
System.out.println(obj.x);
System.out.println(x);
}
}

[/java]

Output :
i got the Child and Parent values in Output
10
20

Add a Comment

Your email address will not be published. Required fields are marked *