본문 바로가기
  • think normal
새로워지기/서른의 생활코딩

ex8) java

by 청춘만화 2012. 2. 14.

1.
public class LocalVariableIntTest {
//class변수를 선언하지않음
public void variablePrint(){
int intValue = 0; //지역변수는 초기화 시켜줘야한다.
System.out.println("LocalVariableIntTest =" +intValue);
}

public static void main(String[] args) {
MemberVariableIntTest local= new MemberVariableIntTest();
local.variablePrint();

}
}



2.
public class MemberVariableIntTest {
int intValue; //전역변수는 초기화하지 않아도 자동으로 0을 넣어준다.
public void variablePrint(){
System.out.println("Member Variable intValriable =" +intValue);
}

public static void main(String[] args) {
MemberVariableIntTest member= new MemberVariableIntTest();
member.variablePrint();

}






3. 
public class MemberVariableAutoInit {
boolean booValue;
byte byteValue;
short shortValue;
int intValue;
long longValue;
float floatValue;
double doubleValue;
public void initVlauePrint(){
System.out.println("booValue" +booValue );
System.out.println("byteValue" +byteValue );
System.out.println("shortValue" +shortValue );
System.out.println("intValue" + intValue);
System.out.println("longValue" +longValue );
System.out.println("floatValue" +floatValue );
System.out.println("doubleValue" +doubleValue );
}
public static void main(String[] args) {
MemberVariableAutoInit memberInit = new MemberVariableAutoInit();
memberInit.initVlauePrint();
}

}




4. 
public class VariableScopeTest {
private int intValue1 = 1;
private int intValue2 = 2;
public void firstScopeMethod(){
int intValue1 = 10;
int intValue2 = 20;
int total =intValue1 +intValue2;
System.out.println("firstScopeMethod Total = " + total);
}
public void secondScopeMethod(){
int intValue2 = 200;
int total =this.intValue1 +intValue2;
System.out.println("secondScopeMethod Total = " + total);
}
public void thirdScopeMethod(){
int total =intValue1 +intValue2;
System.out.println("thirdScopeMethod Total = " + total);
}
public static void main(String[] args) {
VariableScopeTest variableScope = new VariableScopeTest();
variableScope.firstScopeMethod();
variableScope.secondScopeMethod();
variableScope.thirdScopeMethod();
}

}

'새로워지기 > 서른의 생활코딩' 카테고리의 다른 글

ex10) java  (0) 2012.02.14
ex9) java  (0) 2012.02.14
java _20120213  (0) 2012.02.14
ex7) java  (0) 2012.02.09
ex6) java  (0) 2012.02.09

댓글