why do we using THIS keyword and SUPER keyword in programming ?

Discussion in 'Object Oriented Concepts' started by radhikadevi, Jan 28, 2011.

  1. radhikadevi

    radhikadevi New Member

    Hi friends :),
    what are the usages of This and Super keywords ? please send your explanations with sample codings ? :mad:
  2. aravindh_san

    aravindh_san New Member

    SUPER Keyword helps you to access the Constructors, Variables & Methods of the base class.
    THIS keyword holds the object of its own class.
  3. ihdubus

    ihdubus New Member

    public class Demo {
    System.out.println("in Demo Constructor");
    public void m1(){
    System.out.println("in m1 of Demo Class");
    public void m2(){
    System.out.println("in m2 of Demo Class");
    public void m3(){
    System.out.println("in m3 of Demo Class");
    public static void main(String[] args) {
    Demo d=new Demo();

    Demo sd=new SubClassOfDemo();

    class SubClassOfDemo extends Demo

    public SubClassOfDemo() {



    public void m1(){

    System.out.println("in m1 of SubClasssDemo Class");
    public void m2(){
    System.out.println("in m2 of SubClasssDemo Class");

  4. srikkanth

    srikkanth New Member

    hii radika..

    about "this" :

    If we create any object, internally a reference variable "this" will created and it points to the object.. so we can say ''this'' is a keyword that points to the current object. Suppose we hav created an object as Radhika rad=new Radhika(); then internally 2 reference variables "rad" and "this" will be pointed to the Radhika object. So by using "this" we can access members of Radhika object.

    class Sample {
    int i;
    int j;
    Sample(int i, int j) {
    class Demo {
    public static void main(String args[]) {
    Sample s=new Sample(10,20);

    about "super" :

    "super" is a keyword used to access the super class members..
    why super keyword?? --? Suppose we hav a super class and sub class having a method with same name, then from subclass if we want to acess the super class method, we need to use the suer keyword for accesing the super class method.
    We can acess the super class members from subclass as super.variable,super.method(),super(values)...
    class SupCls {
    sameMethod(){ }
    class SubCls {
    sameMethod() { }
    // calling super class method

    This is small discussion on super and this.. if u want more, contact me on srikkanth.99999@gmail.com
  5. sivaprasadreddys

    sivaprasadreddys New Member

    About this :
    The key word this is useful when you need to refer to instance of class from its method. The keyword (this) helps us to avoid name conflicts. If we declare the name of instance variable and local variable with same name, then we'll get name conflicts. so to avoid it we use keyword <b> this </b>.

    About super :
    A subclass can call a constructor which defined in it's super class by using the following statement.
    super() must always be the first statement that is executed inside a subclass' constructor.
  6. johnpaulmathew

    johnpaulmathew New Member

    The super keyword in java programming language refers to the superclass of the class where the super keyword is currently being used.
    THIS keyword holds the object of its own class.
  7. madhavan

    madhavan New Member

    This :

    This is used to refer the current class instance . For an Example

    this.getName(); is use to access the getName() method for the current ClassInstance.

    Super :

    Super keyword is used to call immediate parent.
    Super keyword can be used with instance members i.e., instance variables and instance methods.
    Super keyword can be used within constructor to call the constructor of parent class.
  8. anneroberts

    anneroberts Member

    This will be a Pivotal word done java. It camwood a chance to be utilized inside the strategy alternately constructor for population. It(this) meets expectations Likewise An reference to the present item whose technique alternately constructor is, no doubt conjured. It is utilized inside An sub-class technique definition to call a strategy characterized in the super population.

Share This Page