응용 SoftWare/JAVA
static
Hyun CHO
2016. 12. 1. 16:07
테스트 클래스
public class StaticTest
{
//변수선언, 객체생성
static String name = "StaticTest 조현";
int ban = 11;
public static String addr = "서울시 양천구 신정동";
static{
//클래스 내에는 실행문을 사용할 수 없지만 static 내로 지정하면 사용할 수 있다.
int a=10+200;
System.out.println("a="+a);
}
public StaticTest(){
System.out.println("Static()생성자 출력");
}
//메소드에 static
public static void output(){
System.out.println(name+"="+addr);
}
}
=====================================================================
메인 클래스
class StaticMain
{
public static void main(String[] args)
{
StaticTest st1 = new StaticTest();
StaticTest st2 = new StaticTest();
StaticTest st3 = new StaticTest();
//Static 있는 메소드는 객체생성하지 않고 클래스명, 메소드명으로 실행할 수 있다.
StaticTest.output();
}
}