> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dart Overridden Method

An overridden method in Dart is an instance method within a subclass that provides a new implementation for a method inherited from its superclass. It allows a subclass to replace or extend the inherited behavior while adhering to the method signature constraints defined by the parent class, enabling runtime polymorphism through dynamic dispatch.

## The `@override` Annotation

Dart utilizes the `@override` metadata annotation to explicitly indicate that a method is intended to override a superclass method. While technically optional, it is a critical compiler directive. If the annotated method fails to correctly match a superclass method signature, the Dart analyzer throws a compile-time error, preventing silent inheritance failures.

## Syntax and Implementation

```dart theme={"dark"}
class BaseClass {
  void processData(String data) {
    print("Base processing: $data");
  }
}

class DerivedClass extends BaseClass {
  @override
  void processData(String data) {
    print("Derived processing: $data");
  }
}
```

## Invoking the Superclass Method

An overridden method can access the original implementation of the superclass using the `super` keyword. This is necessary when the subclass intends to augment rather than completely replace the parent method's execution context.

```dart theme={"dark"}
class DerivedClass extends BaseClass {
  @override
  void processData(String data) {
    // Invokes the overridden method in the parent class
    super.processData(data); 
    print("Additional derived processing: $data");
  }
}
```

## Technical Constraints and Signature Rules

To successfully override a method in Dart, the overriding method must adhere to strict type system rules regarding its signature:

1. **Parameter Matching and Contravariance:** The overriding method must accept all required parameters of the superclass method. It may introduce new optional parameters (either positional or named). Furthermore, standard parameter types are contravariant; the overriding method can declare a parameter as a supertype of the corresponding parameter in the superclass.
2. **Covariant Return Types:** Dart supports return type covariance. The return type of the overriding method can be the same type or a subtype of the return type declared in the superclass method.
3. **Covariant Parameters (with `covariant` keyword):** While standard parameters are contravariant, Dart allows tightening parameter types to a subtype (covariance) in an overridden method if the `covariant` keyword is explicitly applied to the parameter in either the superclass or the subclass. This bypasses standard static type checking for that parameter in favor of runtime checks.

```dart theme={"dark"}
class Animal {}
class Dog extends Animal {}

class BaseProcessor {
  Animal generate() => Animal();
  void consume(Dog dog) {}
  void process(Animal animal) {}
}

class StrictProcessor extends BaseProcessor {
  // Valid: Return type is covariant (Dog is a subtype of Animal)
  @override
  Dog generate() => Dog();

  // Valid: Parameter type is contravariant (Animal is a supertype of Dog)
  @override
  void consume(Animal animal) {}

  // Valid: Parameter type is covariant using the covariant keyword.
  // Also valid: Adding a new optional parameter.
  @override
  void process(covariant Dog animal, [String? extraData]) {}
}
```

## Restrictions

* **Static Methods:** Static methods belong to the class itself, not the instance, and therefore cannot be overridden. They are resolved at compile-time via static dispatch.
* **Constructors:** Constructors are not inherited and cannot be overridden.
* **Private Methods:** Methods prefixed with an underscore (`_`) are library-private. They can only be overridden if the subclass resides within the same library (file) as the superclass.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Dart Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
