반응형

*메소드와 인스턴스

- 객체란 소프트웨어 세계에 구현할 대상을 의미, 클래스는 이를 구현하기 위한 설계도이다.

- 인스턴스란 설계도에 따라 소프트웨어 세계에 구현된 실체를 의미한다.

// 인스턴스 생성
class Main {
	public static void main(String[] args) {
    	Car c1 = new Car();
    }
}

// 메소드 생성
class Car {
	void method1() {
    	System.out.println("method1이 실행됩니다.");
    }
    void method2() {
    	System.out.println("method2이 실행됩니다.");
    }
}


// 메소드 호출
class Main {
	public static void main(String[] args) {
    	Car c1 = new Car();
        c1.method1();
        c1.method2();
    }
}
반응형

'기타' 카테고리의 다른 글

깃허브(github) 사용방법  (0) 2020.06.12
제네릭  (0) 2020.06.08
필드(field)  (0) 2020.06.02
for-each문  (0) 2020.06.02
상수  (0) 2020.06.02

+ Recent posts