Skip to content

Instantly share code, notes, and snippets.

@bigbany
Created April 11, 2022 09:24
Show Gist options
  • Save bigbany/c72f942f46e521584c155d6ae37f3cbe to your computer and use it in GitHub Desktop.
Save bigbany/c72f942f46e521584c155d6ae37f3cbe to your computer and use it in GitHub Desktop.
method oveeride
void main(){
TimesTwo tt = TimesTwo(2);
print(tt.calculate());
TimesFour tf = TimesFour(2);
print(tf.calculate());
}
// method - 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.calculate()*2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment