IT. Expert System.

C#

override


he override modifier is required to extend or modify the abstract or virtual implementation of an inherited method, property, indexer, or event. An override method provides a new implementation of a member that is inherited from a base class. The method that is overridden by an override declaration is known as the overridden base method. The overridden base method must have the same signature as the override method. For information about inheritance, see Inheritance (C# Programming Guide). You cannot override a non-virtual or static method. The overridden base method must be virtual, abstract, or override. An override declaration cannot change the accessibility of the virtual method. Both the override method and the virtual method must have the same access level modifier. You cannot use the new, static, or virtual modifiers to modify an override method. An overriding property declaration must specify exactly the same access modifier, type, and name as the inherited property, and the overridden property must be virtual, abstract, or override.

Syntax:
public override returnType functionName()
{
//body
}


Example:

using System;

class A
{
    public virtual void Y()
    {
	// Used when C is referenced through A.
	Console.WriteLine("A.Y");
    }
}

class B : A
{
    public override void Y()
    {
	// Used when B is referenced through A.
	Console.WriteLine("B.Y");
    }
}

class C : A
{
    public void Y() // Can be "new public void Y()"
    {
	// Not used when C is referenced through A.
	Console.WriteLine("C.Y");
    }
}

class Program
{
    static void Main()
    {
	// Reference B through A.
	A ab = new B();
	ab.Y();

	// Reference C through A.
	A ac = new C();
	ac.Y();
    }
}

/*Result

B.Y
A.Y*/


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 837 / . Delta: 0.02812 с