JAVA
[JAVA] 자바 static member 호출 방법 /static 정의/설명/주의점/사용하기
해병1188기
2021. 4. 6. 12:09
728x90
반응형
2021.03.29 - [JAVA/JAVA(자바)설치 및 툴 이용(ECLIPSE)] - [JAVA] 자바 설치 및 환경 하기 JDK 1.8 버전
[JAVA] 자바 설치 및 환경 하기 JDK 1.8 버전
www.oracle.com/kr/java/technologies/javase/javase-jdk8-downloads.html 위 링크 클릭 하면 여기로 온다 각자의 환경에 맞게 설치 하자 나는 윈도우 64 비트 그전 오라클 로그인 필수 1. 다운로든 된거를 실행..
marine1188.tistory.com
개발 환경
Window 10
JDK 1.8
이클립스 2020_03 버전
> static member 호출 방법 >
객체명.스태틱멤버 또는 스태틱멤버함수()
클래스명.스태틱멤버 또는 스태틱멤버함수()
//static member 에서 일반 멤버변수는 사용 할수없다
public static void view() {
total = total +100;
//count = count + 100
}
//static member 에서는 this 키워드 사용할 수 없다
public static void show(int count,int total) {
this.count = count;
this.total = total;
}
package ex06.staticMember;
class Atm{
int count;
static int total; // static member
public Atm(int amount) {// 생성자 함수
count += amount;// count = count + amount;
total += amount;//total = total +amount
}
//static member 에서 일반 멤버변수는 사용 할수없다
public static void view() {
total = total +100;
//count = count + 100
}
//static member 에서는 this 키워드 사용할 수 없다
public static void show(int count,int total) {
this.count = count;
this.total = total;
}
public void display() {
System.out.println("count ="+count);
System.out.println("total ="+total);
}
}
public class MainEntry {
public static void main(String[] args) {
// 생성자 함수로 돌아간다
System.out.println(Atm.total);
Atm at = new Atm(1000);// 천원 개설
at.display();
System.out.println("===========");
Atm at2 = new Atm(1000);//
at.display();
System.out.println("===========");
Atm at3 = new Atm(1000);//
at.display();
System.out.println("===========");
}
}
728x90
반응형