CLASS (2) 썸네일형 리스트형 Week4) Java Programming Lab : Class and Instance (2) Class Constructor 모든 클래스는 반드시 하나 이상의 contructor을 가짐 사용자가 클래스 선언시 구성자를 선언하지 않은 경우 자바 컴파일러가 디폴트 구성자를 만듦 초기에 멤버 변수를 초기화 모든 변수를 초기화하지 않은 경우, 초기화되지 않은 값은 디폴트 값으로 자동 설정 this 모든 객체는 자기 자신을 참조할 때 this 키워드를 사용 2. constructor, set, get example public class StuentData { private String StudentName; private int StudentID; private int StudentAge; // constructor1 - 변수 초기화 public StudentData(){ StudentName = "N.. Week3) Java Programming Lab : Class and Instance 1. Introduction to Class class 프로그래머가 정의하는 특별한 타입 변수가 클래스 타입으로 선언될 수 있다. 클래스는 해당 타입의 객체가 가지고 있는 데이터와 수행할 함수를 결정한다. 클래스 타입의 값 = object (객체), instance (인스턴스) example class Ball: fields : color, size, shape methods : set_ball_color(), set_ball_size(), set_ball_shape() // instances of the class Ball : football, tennis ball, rugby ball etc... methods 들은 fields의 데이터 값들을 변경하는 역할을 한다. 클래스는 데이터 값을 변경하여 다.. 이전 1 다음