Please Clear my one doubt related to Inheritance
class Parent {
	int x;
	int y;

	public Parent() {
		this.x = 5;
		this.y = 5;
		System.out.println("In parent Constructor");
	}
	public void print(int a, int b) {
		System.out.println("Parent class, Print method, a and b");
	}
}

public class Child extends Parent {
	int x;
	int y;

	public Child() {
		this.x = 10;
		this.y = 10;
		System.out.println("In Child constructor");
	}
	public void print(int a, int b) {
		System.out.println("Child class, Print method, a and b");
	}
	
	public static void main(String[] args) {
		Parent obj = new Child();
		System.out.println(obj.x);
		System.out.println(obj.y);
		obj.print(0, 0);
	}
}

Here why output Coming like this -
In parent Constructor
In Child constructor
5
5
Child class, Print method, a and b

For value of x and y
the output must come 10 and 10 na

Comments (1)