0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

thisを使う!!

Posted at

▪️ thisとは
 PHPでスコープ外で定義された変数を利用するための擬似変数。
 簡単に言うなら英語の省略に近いイメージ。

例えば、あなたは長い映画を見るのが好きですか?と聞かれ、私は長い映画を見るのが好きです。と答えているとめんどくさいと思います。
好きです!と省略したいですよね?
その感覚で使うのがthisになります!

<書き方>
下記のようになる:writing_hand_tone2:

public class Monster {
int hp = 100;
int mp = 20;
Monster(int hp ,int mp){
this.hp = hp;//1
this.mp = mp;
}

コード引用元:https://qiita.com/kajirikajiri/items/85b911688155f9fc251a

今日の投稿は以上です。

wagaでした!!

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?