Program:-
class Base{
int x;
public int getX() {
return x;
}
public void setX(int x) {
System.out.println("I am in base class and setting x now ");
this.x = x;
}
public void printMe(){
System.out.println("I am a Method from Base class ");
}
}
class Derived extends Base{
int y;
public int getY() {
System.out.println("I am in derived class and setting y now ");
return y;
}
public void setY(int y) {
this.y = y;
}
}
public class InheritanceV45 {
public static void main(String[] args) {
//Creating an object of base class.
Base a = new Base();
a.setX(4);
System.out.println(a.getX());
//creating an object of Derived class.
Derived b = new Derived();
b.setX(43);
System.out.println(b.getX());
b.setY(34);
System.out.println(b.getY());
}
}

