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 5 years have passed since last update.

クラスまとめ①

0
Last updated at Posted at 2020-01-06

【クラスとは】

→もの一般に関するデータ(変数)と機能(メソッド)をまとめたもの
→あくまでも設計書としての抽象的なもの

//クラス定義
class クラス名{
メンバ;
}

【オブジェクト】

→クラスを基にした具体化
→一つのクラスからオブジェクトはいくらでも作成可能
→オブジェクトはクラス型の変数(参照型変数)

//オブジェクト化
クラス名 オブジェクト名 = new クラス名();

//メンバの利用
オブジェクト名.フィールド = 値;
オブジェクト名.メソッド();

【メソッド】

→メソッドは処理をまとめたもので、呼び出すとその処理を実行

void メソッド名(){処理}

→同クラス内のメソッドAからメソッドBを呼び出すことも可能

class test{
void メソッドA(){}
void メソッドB(){this.メソッドA();}
}

※同クラス内のとき変数やメソッドを呼び出すときthis.メンバ名;とthisをつける
→メソッド()内に引数という変数を記述でき、その変数を処理に利用可能(引数はいくらでも定義可能)

void メソッド名(型名 引数1, 型名 引数2){}

→引数とは逆にメソッドから返される情報を戻り値という
※returnを使うことで一つだけ戻り値を返せる
※戻り値を使うときは戻り値の型を定義する必要あり
※voidは型指定なしを意味する

戻り値型 メソッド名(){
return 戻り値;
}
0
0
0

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?