Overriding Methods

 ///Subclasses can override instance methods (including operators), getters, and setters.

///You can use the @override annotation to indicate that you are intentionally overriding a member.

void main() {
var obj = B();
obj.display();
}
class A {

@override
void display() {
print("CLASS A");
}
}
class B extends A {

@override
void display() {
super.display(); // Accessing Super class(parent class) method in sub class(child class) using "super" keyword
print("CLASS B");
}
}

///Advantages of super keyword:
// It can be used to access the data members of parent class when both parent and child have member with same name.
// It is used to prevent overriding the parent method.
// It can be used to call parameterized constructor of parent class.
///Syntax:
// // To access parent class variables
// super.variable_name;
// // To access parent class method
// super.method_name();

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter