JAVA class 예제

*** 검색어: JAVA, class, 클래스, 예제

Ex01.java

public class Ex01 {
	int a;
	double b;
	
	Ex01() {
		a = 100;
		b = 100.0;
	}
	
	Ex01(int x) {
		a = x;
		b = 100.0;
	}
	
	Ex01(int x, double y) {
		a = x;
		b = y;
	}
	
	public void disp(){
		System.out.println("a = " + a);
		System.out.println("b = " + b);		
	}
	
}


Ex02.java

public class Ex02 {
	public static void main(String[] ar) {
	Ex01 kor = new Ex01();
	Ex01 kor1 = new Ex01(10);
	Ex01 kor2 = new Ex01(10, 200.0);
	
	kor.disp();
	kor1.disp();
	kor2.disp();
	}
}


출력 결과
a = 100
b = 100.0
a = 10
b = 100.0
a = 10
b = 200.0

댓글

Designed by JB FACTORY