super keyword

With a super keyword, you have access(reference) to your parent class. In addition to super, you benefit invoking the methods, variables of the parent class.

Example:

public class A  extends B{

	A(int a,int b) {
		super(a, b);
} }
public class B {
private int a;
private int b;
	B(int a,int b){
		this.setA(a);
		this.b = b;
	}
	public int getA() {
		return a;
	}
	public void setA(int a) {
		this.a = a;
	}
}
public class Main {

	public static void main(String[] args) {
	A A_Class = new A(2,2);

   System.out.println(A_Class.getA());
	}

}




Output is: 2

Leave a Reply