본문 바로가기
비트 단기/java

java class시작

by woohyun22 2018. 11. 27.


13번


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package Pack01;
import java.util.concurrent.SynchronousQueue;
class Tiger{//클래스 생성 첫자는 대문자로한다.
    
}
 
public class Hello {
    /*class tiger{
            여기 넣으면 안된다.
        }*/
    public static void main(String[] args) {
    }
}
 
 
cs


14번


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package Pack01;
import java.util.concurrent.SynchronousQueue;
class Tiger{
    //1번 생성자
    
    
    //2번 field(변수)
    int a,b;    
    
    //3번 method(함수)
    void func01() {
        System.out.println("함수콜");
    }
    //a와 b와 func는 Tiger class의 멤버(가족)다.
}
public class Hello {
    public static void main(String[] args) {
        
    }
}
 
 
cs


15번


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package Pack01;
import java.util.concurrent.SynchronousQueue;
class Tiger{//이 클래스는 설계도일 뿐이다. 메모리 소모x
    int a,b;    
    void func01() {
        System.out.println("함수콜");
    }
}
public class Hello {
    public static void main(String[] args) {
        Tiger t1 = new Tiger();//t1은 객체이름 t1 = 비행기이름
        System.out.println(t1.a+" "+t1.b);//객체는 0으로 초기화되어서 생성된다.
        t1.a = 10;
        t1.b = 20;//객체안의 변수쓸때는 .체이닝 해서 써야된다.
        System.out.println(t1.a+" "+t1.b);
        t1.func01();
        for (int i = 0; i < 5; i++) {
            t1.func01();
        }
        //new ctrl space
        Tiger n1 = new Tiger();
    }
}
 
 
cs


16번


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package Pack01;
import java.util.concurrent.SynchronousQueue;
class Tiger{
    int a,b;
    void func01() {
        System.out.println("함수1콜");
    }
    void func02(int x,int y) {
        System.out.println("함수2콜");
        System.out.println(x+" "+y);
    }
    int func03() {
        return 99;
    }
}
public class Hello {
    public static void main(String[] args) {
        Tiger t1 = new Tiger();
        t1.a=10;
        t1.b=20;
        System.out.println(t1.a+" "+t1.b);
        t1.func01();
        t1.func02(100,200);
        t1.func03();
        //함수 출력 방식 3
        int n=t1.func03();
        System.out.println(n);
        System.out.println(t1.func03());
    }
}
 
 
cs


728x90

'비트 단기 > java' 카테고리의 다른 글

24~ 31  (0) 2018.11.29
java class 2 17~24  (0) 2018.11.28
java 2 10~  (0) 2018.11.27
java 1  (0) 2018.11.26
java설치 최신 , 환경변수 이클립스  (0) 2018.11.26

댓글