Created
April 11, 2022 09:24
-
-
Save bigbany/c72f942f46e521584c155d6ae37f3cbe to your computer and use it in GitHub Desktop.
method oveeride
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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