overwrite

Summary

The overwrite modifier is used for method hiding/shadowing (early binding).

Syntax

overwrite member

Parameters

member
The member to attempt to overwrite.

Description

The overwrite keyword specifies a new implementation for a method inherited from a base class via early binding. It is also used for explicitly specifying the implementation for interface methods.

The overwrite keyword is used in contrast to override and final which specify late binding.

Examples

Method Hiding via Early Binding
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
external $; // jQuery
 
class Animal
{
    protected var $element = $('<div class="animal-icon"></div>');
 
    public void render() {
        $("#content").append($element);
    }
}
 
class Dog : Animal
{
    private string name;
 
    public Dog(string name) {
        this.name = name;
    }
 
    public overwrite void render() {
        $element.attr("title", name);
        $("#content").append($element);
    }
}

See Also

Share

HTML | BBCode | Direct Link