객체 지향 프로그래밍에서는 모든 데이터를 객체(object)로 취급하며, 이러한 객체가 바로 프로그래밍의 중심이 됩니다.
객체(object)란 간단히 이야기하자면 실생활에서 우리가 인식할 수 있는 사물로 설명할 수 있습니다.
이러한 객체의 상태(state)와 행동(behavior)을 구체화하는 형태의 프로그래밍이 바로 객체 지향 프로그래밍입니다.
이때 객체를 만들어 내기 위한 설계도와 같은 개념을 클래스(class)라고 합니다.
public class 클래스이름 { // 멤버 변수 int a; int b; // 생성자 클래스이름(){ a=10; b=15; } // 메서드 public static void main(String[] args){ //프로그램 시작 시점 } }
멤버변수
클래스 안의 기능을 끄집어 내서 사용할 때 사용.
저장할 공간.
(ex. 화면에 출력 시 사용했던 System.out.println()에서 out은 System이라는 클래스의 out이라는 멤버변수를 사용한 것이다.)
메서드(method)
기능을 나타낸다.
()가 항상 붙어있다.
(ex. System.out.println에서 println()이다.)
생성자(constructor)
처음에 값을 넣어줄 때 사용(default 값)
ex)<p>class Person{ String eyes="눈"; String ears="귀"; String nose="코"; String mouth="입"; void useEyes(){ System.out.println(eyes+"으로 봄"); } void useEars(){ System.out.println(ears+"로 소리를 들음"); } void useNose(){ System.out.println(nose+"로 냄새를 맡음"); } void useMouth(){ System.out.println(mouth+"으로 욕을 함"); } }