Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Why we don't use " this.field" in here

$
0
0
I have a code in here.

public class PersonalDetails {

    private String name;
    private int age;
    private String gender;
    private String qualification;

    public PersonalDetails(String name, int age, String gender, String qualification) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.qualification = qualification;
    }

    public int getAge() {
        return age;
    }

    public String isGender() {
        return gender;
    }

    public String getName() {
        return name;
    }

    public String getQualification() {
        return qualification;
    }

    public static void main(String[] args) {
        PersonalDetails person = new PersonalDetails("The Anh", 20, "Male", "Studying");

        System.out.println("Name: " + person.getName()
                + "\nAge: " + person.getAge()
                + "\nGender: " + person.isGender()
                + "\nQualification: " + person.getQualification());

    }
}


I want to ask why we write
public String getName() {
        return name;
    }


instead of

public String getName() {
        return this.name;
    }

?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>