방치하기

매소드 오버로딩 본문

홍익대 Java/수업

매소드 오버로딩

Yi Junho 2009. 7. 17. 16:18
반응형
class NumBer

{
	private int num1;
	private int num2;

	public void swap()
	{
		int swap=num1;
		num1=num2;
		num2=swap;

	}
	public void getNum1 (int new_num)
	{
		num1=new_num;

	}
	public int getNum1()
	{
		return num1;
		
	}
	public void getNum2 (int new_num)
	{
		num2=new_num;

	}
	public int getNum2()
	{
		return num2;
		
	}
}






public class NumBerTest
{

	public static void main (String [] args)
	{
		NumBer a;
		a= new NumBer();
		
		a.getNum1(1);
		a.getNum2(26);
		
		System.out.println(a.getNum1() +" "+ a.getNum2());
		
		System.out.printf("%d %d \n",a.getNum1(),a.getNum2());
		
		a.swap();
		
		System.out.println("스왑 이용후 데이터\n"+a.getNum1());
		System.out.println(a.getNum2());

	}
		
}
반응형
Comments