피드로 돌아가기
새로워지기·서른의 생활코딩

ex5) java_oop

NS
normalstory
표지 이미지

/*
class Box {
int width;
int height;
int depth;
long idNum;              // ->| 4개의 접근지정자가 생략된 데이터 맴버 
// new 연산자가 선언될때마다 메모리 생성
static long boxID = 0; // (static 데이터 맴버 = 클래스 변수) 선언 !!
public Box() {                   // 생성자는 결과형(void) 사용불가 
idNum = boxID++;    //앞에 this.이 생략되있다.
// 생성자가 수행될 때마다 클래스 변수의 값을 증가
}
public void Dispaly(){
System.out.println( width +""+ height +""+ depth +"="+idNum);
}
}
public class Oop01 {
public static void main(String[] args) {
//System.out.print(b1.boxID);  //아직 선언이 안되어서 -> 에러!
System.out.print(Box.boxID);  //같은 기억공간을 의미한다.
Box b1 = new Box();
//Box b1 = new Box(12);   // 해당 생성자가 없음으로 에러!
Box b2 = new Box();
b1.Dispaly();
b2.Dispaly();
System.out.print(b1.boxID);  //선언이 되어서 -> 성공
System.out.print(b2.boxID);  //같은 기억공간을 의미한다.
System.out.print(Box.boxID);  //같은 기억공간을 의미한다.
}

}

**/




class Box {
int width;
int height;
int depth;
long idNum;               // ->| 4개의 접근지정자가 생략된 데이터 맴버 
// new 연산자가 선언될때마다 메모리 생성
static long boxID = 0; // (static 데이터 맴버 = 클래스 변수) 선언 !!
public Box() {                  // 결과형(void) 사용불가 
idNum = boxID++;   //앞에 this.이 생략되있다.
                             // 생성자가 수행될 때마다 클래스 변수의 값을 증가
}
public void Dispaly(){
System.out.println( width +""+ height +""+ depth +"="+idNum);
}
}
public class Oop01 {
static{                 //메모리에 계속 담겨있다가, 프로그렘 종료할때 삭제한다.
System.out.println(Box.boxID);
System.out.println("메인함수 수행 이전에 메모리가 먼저 정의되었으므로 접근가능");
                 //System.out.println(b1.boxID); //아직 new가 선언되지 않았다.
}
public static void main(String[] args) {
//System.out.println(b1.boxID);  //아직 선언이 안되어서 -> 에러!
System.out.println(Box.boxID);   //같은 기억공간을 의미한다.
Box b1 = new Box();
//Box b1 = new Box(12);         // 해당 생성자가 없음으로 에러!
Box b2 = new Box();
b1.Dispaly();
b2.Dispaly();
System.out.println(b1.boxID);    //선언이 되어서 -> 성공
System.out.println(b2.boxID);    //같은 기억공간을 의미한다.
}

}

  • Open in Google Docs Viewer
  • Open link in new tab
  • Open link in new window
  • Open link in new incognito window
  • Download file
  • Copy link address
  • Edit PDF File on PDFescape.com

element

Font
font-family
font-size
font-style
font-variant
font-weight
letter-spacing
line-height
text-decoration
text-align
text-indent
text-transform
white-space
word-spacing
color
Background
bg-attachment
bg-color
bg-image
bg-position
bg-repeat
Box
width
height
border-top
border-right
border-bottom
border-left
margin
padding
max-height
min-height
max-width
min-width
outline-color
outline-style
outline-width
Positioning
position
top
bottom
right
left
float
display
clear
z-index
List
list-style-image
list-style-type
list-style-position
Table
vertical-align
border-collapse
border-spacing
caption-side
empty-cells
table-layout
Effects
text-shadow
-webkit-box-shadow
border-radius
Other
overflow
cursor
visibility
친절한 찰쓰씨
글쓴이
친절한 찰쓰씨
친절한 찰쓰씨 · 일상 UX 디자이너
기획·디자인·단상을 조용히 기록합니다.
작가 페이지에서 더 보기

이어서 읽기

새로워지기

꾸준히, 오래, 지치지 않고

Mar 31, 2026·8
새로워지기

테크 라이프 발란스

Feb 7, 2026·3
새로워지기

휴탈리티 박정렬

Feb 7, 2026·11