Results 1 to 2 of 2
  1. #1
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default Use super. or this.

    Say i have two classes:

    Java Code:
    public class A {
      protected String name;
    }
    
    public class B extends A {
      // here i want to use the name defined in the parent, how should i reference it
      // should i use super:
      super.name;
    
      // or should i use this
      this.name;
    }
    Which one is better and why? Both work correctly!
    Greetings
    Marcus:cool:

  2. #2
    Felissa is offline Member
    Join Date
    Jun 2007
    Posts
    95
    Rep Power
    0

    Default

    Personally, I would use super when calling methods that exist in the parent class...and use "this" when referring to methods that exist in the same class.

    You should look at Java Convention for more clarifications

    Greetings.
    Felissa:p

Similar Threads

  1. Super CSV 1.20
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-27-2007, 08:22 PM
  2. Super CSV 1.15
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-16-2007, 06:37 PM
  3. error with super.xxxxx
    By Rgfirefly24 in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 08:13 AM
  4. difference between this and super
    By mrark in forum New To Java
    Replies: 1
    Last Post: 06-27-2007, 05:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •