super vs this : super « Modifiers « SCJP






class SuperClass {
  String s = "super";

  void display(String s) {
    System.out.println("super: " + s);
  }
}

class ThisSuper extends SuperClass {
  String s = "this";

  ThisSuper() {
    display(this.s);
    display(super.s);
    this.display(s);
    super.display(s);
  }

  void display(String s) {
    System.out.println("this: " + s);
  }
}

public class MainClass {
  public static void main(String[] argv) {
    new ThisSuper();

  }
}
this: this
this: super
this: this
super: this








3.10.super
3.10.1.super is used to reference methods and field from superclass
3.10.2.Using super keyword refers to the constructor from superclass
3.10.3.super vs this