2008년 10월 28일
9주차 수업정리! 메소드방식
class Box
{
int width;
int height;
int depth;
long idNum;
static long boxID=100; // static으로 선언하여 현제 이쪽에서만 사용하게 만든다.
public static long getCurrentID()
{
return boxID++;
}
}
class StaticMethodDemo {
public static void main(String[] args)
{
Box r1 = new Box();
r1.idNum = Box.getCurrentID();
System.out.println("초기값 : " + r1.idNum + "입니다.");
Box r2 = new Box();
r2.idNum = Box.getCurrentID();
System.out.println("마지막값 : " + r2.idNum + "입니다.");
System.out.println("다음번 객체의 idNum은 :" + r2.getCurrentID() +"입니다.");
}
}
------------------------------------------------------------------------------------------------------
class One
{
int value;
public One()
{
this(100);
}
public One(int value)
{
this.value=value;
Another.methodA(this);
}
}
class Another
{
static void methodA(One ins)
{
System.out.println("값은" + ins.value + "입니다.");
}
}
class OneTest
{
public static void main(String[] args)
{
int value;
One r1 = new One();
System.out.println("One test에서의 값은" + r1.value + "이다");
value = Integer.parseInt(args[0]);
One r2 = new One(value);
System.out.println("one test에서의 값" + r2.value + "이다");
}
}
public 과 private는 객체생성이 되었을때 사용할수 있는것이고 , static은 객체의 생성없이.. 그값을 바로 사용할수 있다.
따라서.. 위쪽에 static은 객체가 없으므로 static을 사용하여야 한다.
Integer.parseInt(args[0])는 접근할때 사용하는것이다...
# by | 2008/10/28 15:59 | java프로그램밍 | 트랙백 | 덧글(1)



