1)
void main() {
TimesTwo tt = TimesTwo(2);
print(tt.calculate());
TimesFour tf = TimesFour(2);
print(tf.calculate());
}
// method - function (class 내부에 있는 함수)
// override - 덮어쓰다 (우선시하다)
class TimesTwo {
final int number;
TimesTwo(
this.number,
);
// method
int calculate() {
return number * 2;
}
}
class TimesFour extends TimesTwo {
TimesFour(
int number,
) : super(number);
@override
int calculate() {
// return super.number*4; // 이게 정석이지만 아래로 표현할 수 있다!!!
// return number * 4;
return super.calculate() * 2; // 이렇게 쓸수도 있다!!!
}
}

'개발이 좋아서 > Flutter가 좋아서' 카테고리의 다른 글
[Dart] 3일차_객체지향_상속_interface (0) | 2022.12.14 |
---|---|
[Dart] 3일차_객체지향_상속_static (0) | 2022.12.14 |
[Dart] 2일차_객체지향_상속 (0) | 2022.12.12 |
[Dart] 2일차_객체지향_getter/setter (0) | 2022.12.12 |
[Dart] 2일차_객체지향 (0) | 2022.12.12 |