Created
January 29, 2024 02:44
-
-
Save doyle-flutter/7b660e0e124bcb216b1bcbc7b51b1055 to your computer and use it in GitHub Desktop.
class01 extends
This file contains 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(){ | |
Parent p1 = Parent(); | |
Child c1 = Child(); | |
Parent pc1 = Child(); | |
p1.a; | |
// p1.b; // err -> only child | |
p1.func(); | |
p1.func3(); | |
// p1.func2(); // err -> only child | |
p1.func4(); | |
c1.a; | |
c1.b; | |
c1.func(); | |
c1.func2(); | |
c1.func3(); | |
print( c1.func4() ); | |
// ------------------------------------------------------ | |
final p2 = Parent2(a:1); | |
final c2 = Child2(a: 2); | |
} | |
class Parent{ | |
int a = 11; | |
void func() => print(this.a); | |
void func3() => print(this.a); | |
int func4() => this.a*2; | |
} | |
class Child extends Parent{ | |
int b = 22; | |
void func2() => print(this.a+this.b); | |
@override | |
void func3() => print(this.a * this.b); | |
@override | |
int func4() => super.func4() * 2; | |
} | |
class Parent2{ | |
final int a; | |
Parent2({required this.a}); | |
} | |
class Child2 extends Parent2{ | |
// (1) | |
Child2({required super.a}); | |
// (2) | |
// Child2({required int b}) : super(a: b); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment