Home / java / Access Parent class Variables in child class

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


class base
{
int x=10;
}

Child Class


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);
}
}

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

About Mohammad Fareed

Software Engineer @ Tekzenit.

Check Also

Object Creation in Java

1)How many ways are there to create an object? 1. How many ways to create …

Leave a Reply

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