Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter01 : person / personmain 본문

JAVA/chapter11_reference_array

chapter01 : person / personmain

GAWON 2023. 5. 26. 18:17
package org.joonzis.ex;

public class Ex01_Person {
	// 필드
	String name;
	int age;
	double height;
	char gender;
	
	public Ex01_Person() {}
	public Ex01_Person(String name, int age, double height, char gender) {
		this.name = name;
		this.age = age;
		this.height = height;
		this.gender = gender;
	}
	void output() {
		System.out.println("이름 : " + name);
		System.out.println("나이 : " + age);
		System.out.println("키 : " + height);
		System.out.println("성별 : " + gender);
	}
	
}
package org.joonzis.ex;

public class Ex01_PersonMain {
	public static void main(String[] args) {
		
		Ex01_Person person1 = new Ex01_Person("김씨", 20, 130, '남');
		Ex01_Person person2 = new Ex01_Person("이씨", 30, 170, '여');
		Ex01_Person person3 = new Ex01_Person("박씨", 40, 190, '남');
		
		person1.output();
		person2.output();
		person3.output();
		
		System.out.println("------------------------");
		
		// 크기 3의 참조 배열 people을 선언 후 값 입력
		// 각 배열 내 데이터 출력
		Ex01_Person[] people = new Ex01_Person[3];
		people[0] = new Ex01_Person("김씨", 20, 130, '남');
		people[1] = new Ex01_Person();
		
		
		for(int i=0; i<people.length; i++) {
			people[i] = new Ex01_Person();
		}
		
		people[0].output();
	}
}

'JAVA > chapter11_reference_array' 카테고리의 다른 글

Test . reference_array  (0) 2023.05.26
chapter03 : Student / StudentMain / StudentManager  (0) 2023.05.26
chapter02 : Triangle / TriangleMain  (0) 2023.05.26