1
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?

java初学者の学習メモ

Last updated at Posted at 2024-11-03

概要

今回はjavaで基礎学習用のコードを書いてみました。
これから少しずつjavaの学習記録を残してまいります。
学習のメモ程度に記述していますのでご承知ください。

実行環境

・windows:Windows11Pro 23H2
・java:22.0.1
・統合開発環境:Eclipse

クラス

Sample.java
package helloworld;

public class Sample {

	public static void main(String[] args) {
		Car.getinitnum();
		Car car1 = new Car();
		car1.setNum();
		int get_num= car1.getNum();
		System.out.println("get_num >>>" + get_num);
	}

}

Car.java
package helloworld;

public class Car {
	//クラス変数
	public static int initnum = -1;
	//カプセル化
	private int num;
	//コンストラクタ
	public Car() {
		num = 10;
		System.out.println("create car,num>>>" + num);
	}
	//getter
	public int getNum() {
		return num;
	}
	//setter
	public void setNum() {
		num = 99;
	}
	//クラスメソッドにはstaticをつける
	public static void getinitnum() {
		System.out.println("initnum>>>" + initnum);
	}
}


出力結果.txt
initnum>>>-1
create car,num>>>10
get_num >>>99
1
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
1
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?