super vs this : super « Modifiers « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Modifiers » super 
3.10.3.super vs this
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.