Developer community
0 votes
706 views
asked by Guru (24.6k points) 29 51 78 | 706 views

1 Answer

0 votes
 
The following example shows how to use this to reference instance variable.
 
 
class Person{
    private String name;
 
 
    public Person(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}
public class Main{
    public static void main(String[] args) {
        Person person = new Person("Java");
        System.out.println(person.getName());
        person.setName("new name");
        System.out.println(person.getName());
    }
}
 
answered by Sr Member (5k points) 7 9 12

Related questions

0 votes
1 answer
asked by rock Expert (15k points) 15 23 31 | 14 views
0 votes
1 answer
asked by augustaina Sr Member (4.8k points) 10 23 31 | 4k views
0 votes
1 answer
asked by sunny Expert (11.4k points) 14 22 29 | 4.2k views
+1 vote
1 answer
asked by augustaina Sr Member (4.8k points) 10 23 31 | 4.3k views
+1 vote
1 answer
asked by augustaina Sr Member (4.8k points) 10 23 31 | 4.4k views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,751 questions
4,046 answers
117 comments
10,709 users