Ms'Note

Object-1 본문

IT/└▶Example Coding.JAVA

Object-1

Jelly_B 2020. 8. 1. 21:38

멤버변수만 포함하고 있는 클래스의 작성예시

  • 학생 정보를 포함하는 클래스의 작성
class Student {
    /** 멤버변수의 선언 + 할당 */
    // 문장을 표현할 수 있는 변수형
    String name = "자바학생";
    int age = 19;
}

public class Main01 {
    public static void main(String[] args) {
       /** 객체의 선언과 할당의 분리 */
       Student std;
       std = new Student();
       
       /** 객체의 생성 (일괄지정) */
       // Student std = new Student();
       
       System.out.println("이름 : " + std.name);
       System.out.println("나이 : " + std.age);
    }
}

 

 

출력 결과

이름 : 자바학생
나이 : 19

'IT > └▶Example Coding.JAVA' 카테고리의 다른 글

Object-3  (0) 2020.08.01
Object-2  (0) 2020.08.01
Method-4  (0) 2020.08.01
Method-3  (0) 2020.08.01
Method-2  (0) 2020.08.01
Comments