class BaseClass {
protected int x; // Integer variable in the base class
// Constructor for the base class
public BaseClass(int x) {
this.x = x;
}
// Method to display the value of x in the base class
public void show() {
System.out.println("BaseClass - Value of x: " + x);
}
}
class SubClass extends BaseClass {
// Constructor for the subclass
public SubClass(int x) {
super(x); // Call the constructor of the base class
}
// Method to display the value of x in the subclass
@Override
public void show() {
System.out.println("SubClass - Value of x: " + x);
}
}
public class superkeywo {
public static void main(String[] args) {
// Create instances of the base class and subclass
BaseClass baseObj = new BaseClass(10);
SubClass subObj = new SubClass(20);
// Call the show() method for the base class
baseObj.show();
// Call the show() method for the subclass
subObj.show();
}
}
Top comments (0)