[Groovy]クラスでthisキーワードを使用する
書式
this.メンバー変数 =値
使用例
class Arkgame {
//変数の宣言
int age =456;
//メソッドを定義
public int getAge() {
//thisキーワードを使用
this.age =123
return age;
}
static void main(String[] args) {
//インスタンスagを生成
Arkgame ag = new Arkgame();
//getAgeメソッドを呼び出す
println(ag.getAge());
}
}
class Arkgame {
//変数の宣言
int age =456;
//メソッドを定義
public int getAge() {
//thisキーワードを使用
this.age =123
return age;
}
static void main(String[] args) {
//インスタンスagを生成
Arkgame ag = new Arkgame();
//getAgeメソッドを呼び出す
println(ag.getAge());
}
}
class Arkgame { //変数の宣言 int age =456; //メソッドを定義 public int getAge() { //thisキーワードを使用 this.age =123 return age; } static void main(String[] args) { //インスタンスagを生成 Arkgame ag = new Arkgame(); //getAgeメソッドを呼び出す println(ag.getAge()); } }
結果
123