클레스 처음 배우면 나오는 예제
class Car {
String name;
int price;
int maxSpeed;
Car({required this.name, required this.price, required this.maxSpeed});
void sale(){
price = (price * 0.9).toInt();
}
}
void main() {
Car bmw = Car(name: 'x5', price: 1000, maxSpeed: 250);
print (bmw.name);
print (bmw.price);
bmw.sale();
print ('세일 후 가격 ${bmw.price}');
bmw.sale();
print ('세일 후 가격 ${bmw.price}');
bmw.sale();
print ('세일 후 가격 ${bmw.price}');
}
'flutter_프로젝트 > 0_초보_코드모음' 카테고리의 다른 글
flutter 코드모음 - 로컬에서 json 읽어오기 (0) | 2025.03.23 |
---|---|
flutter 코드 모음 - 그림을 표시 + 버튼을 누르면 회전 (0) | 2025.03.15 |
dart : 클레스 (0) | 2025.03.05 |