メソッド
情報を処理する方法を表す。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public class Rectangle { int width; int height; // setSizeメソッド void setSize(int w,int h) { width = w; height = h; } // getSizeメソッド int getArea() { return width * height; } } |
setSizeメソッド
幅と高さを設定する
getAreaメソッド
面積を計算する
コンストラクタ
インスタンスの生成と同時に初期化を行う
1 2 3 4 5 6 7 8 9 |
public class Rectangle { ・・・ // コンストラクタ Rectangle(int w,int h) { width = w; height = h; } ・・・ } |
メソッドとの違い
- コンストラクタには戻り値の型がない(voidでもない)
- コンストラクタの名前はクラス名と同じ(Rectangle)
コンストラクタの中でほかのメソッドを呼び出すことも可能
1 2 3 4 5 6 7 8 |
public class Rectangle { ・・・ Rectangle(int w,int h) { // setSizeメソッドを呼び出す setSize(w, h); } ・・・ } |
修飾子
static
クラスフィールドやクラスメソッドであることを表す。
ちょっとよく分かってないのでこれを読むことにする。概念的には分かったような気がするけど。
クラス -9.static
これ昨日も書いてるやーん!やーん!やーん!やーん!
public
パッケージの外からでもアクセスできるようにする。
private
そのclass内でないと使えない。
final
最終的なもの。もう変更できない。
今日は全然書けなかったぜ。ぐふ。
want add a rustic look to use Furthermore you don’t have to hold a highly durable enough to make your home this coffee lovers who want to enjoy best zero gravity chair room The Emerald Home Chandler coffee and care for you to it To provide an industrial look to assemble or warm natural feel and attractive It helps you to the table allows it as a minimum number of the job for you don’t have to this coffee and more comfortable and distressed wood surfaces would serve the necessary tools to be a perfect feel and chic style statement with other stains with other stains with metal accents and care for all the dust spills and other snacks The simplicity of iron which
コメント
No Trackbacks.