객체 지향

[Java] 객체 지향 간단 정리
Dec 19, 2023
객체 지향
객체 : object → 존재할 수 있는 모든 것 // 프로그램 적으로는 New해서 띄우는 모든 것
핵심 : 모든 것들을 부품화 시켜서 조립하는 것
객체 = 객체의 상태(state) + 객체의 동작(behavior)
  1. 객체의 상태는 행위(메서드)를 통해서만 변경 되어야 한다.
  1. 객체를 추상화한다.
 
public void exercise(){ } // 메서드의 기본형
package ex04; class Person4 { // 상태 = 변수 private int weight = 100; // private 다른 클래스에서 접근 못하게 함. public int getWeight(){ return weight; } // 행위 = 메서드 public void exercise(){ weight = weight - 10; } } public class OOPEx02 { public static void main(String[] args) { Person4 p4 = new Person4(); System.out.println("p4의 몸무게 : "+p4.weight); p4.exercise(); System.out.println("p4의 몸무게 : "+p4.weight); } }
 
인스턴스(instance) : 클래스로부터 만들어지는 각각의 객체
 
 
Share article
RSSPowered by inblog