Skip to content

05.Class(クラス)

domanthan edited this page Jun 22, 2020 · 1 revision

クラスの基本構成

/*
 * Copyright
 * License などについて記述。
 *
 */

package com.learning.javabasics;

/**
 * ClassABC.java
 * 
 * クラスないようについて記述。
 * クラス名はなるべく名詞。 先頭の文字は大文字アルファベット。
 */
public class ClassABC {
    private int a,b,c;

    /**
     * コンストラクタ。
     * コンストラクタとは英語でConstructor、構造を作る人の意味。ですので、オブジェクトの構造を作る。
     * a = new ClassABC(1,2,3); のように、new という演算子で呼び出す。
     */
    public ClassABC () {
        a = 1;
        b = 2;
        c = 3;
    }

  /**
     * コンストラクタ。
     */
    public ClassABC (int all) {
        this(all,all,all);
    }

    /**
     * コンストラクタ。
     */
    public ClassABC (int a, int b, int c) {
        this.setABC(a,b,c);
    }

    /**
     * ABCをまとめてセットします。
     * これはメソッド(Method、方法)という。
     */
  public void setABC(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    /** 
     *  Aをゲットします。
     */
    public int getA () {
        return a;
    }
}

Clone this wiki locally