┝ 개발 언어/┎ JAVA
1/25 객체지향 클래스 메소드
홍호나
2022. 3. 1. 22:08
이 글은 2019년 홍익대학교 자바 겨울 특강 수업을 메모한 것이다.
당시에는 에버노트에 메모해놨었기 때문에,
티스토리 블로그를 시작하면서 백업해둔다.
객체
값을 가지거나 값을 가지지 않는 모든 것
인식과 미인식을 모두 아울러 존재하는 것
지향
향해가다.
객체 지향 프로그래밍
세상에 존재하는 모든 것들을 향해가는 프로그램 : 세상에 존재하는 모든 것들을 객체를 가지고 프로그래밍 할 수 있다.
package chapter6;
class car {
//멤버 변수
int speed;
int wheel;
int door;
String carname;
//멤버 메소드
void speedup() {
speed++; // s = s+1
}
void speeddown() {
speed--;
}
void speedstop() {
speed = 0;
}
}
public class oop {
public static void main(String[] args) {
int i = 8;
car mycar = new car(); //자동차라는 종으로 mycar, yourcar라는 객체를 만들어낸 것
car yourcar = new car();
mycar.speedup();
mycar.carname = "srento";
System.out.println(mycar.carname + "의 속도는" + mycar.speed);
yourcar.carname = "벤츠";
yourcar.speedup();
yourcar.speedup();
System.out.println(mycar.carname+"의 속도는"+ mycar.speed);
System.out.println(yourcar.carname+"의 속도는"+ yourcar.speed);
}
}