JAVA공부하기 90

 

this의 사용

 

public class ThisTest2

{

int i=4;

 

public static void main(String args[])

{

ThisTest2 obj1 = new ThisTest2();

obj1.mth1();

System.out.println(this.i);

}

 

void mth1()

{

int i=10;

System.out.println("local i=" +i);

System.out.println("Member i=" + this.i);

}

}

 


 

public class ThisTest3

{

public static void main(String[] args)

{

ThisTest3 obj1 = new ThisTest3();

obj1.mth1();

}

public void mth1()

{

int result1= this.mth2(2,4);        // this.메서드

System.out.println(result1);

}

public int mth2(int v1, int v2)

{

int v3=v1+v2;

return v3;

}

}

 

 

 

+ Recent posts