АкушерствоАнатомияАнестезиологияВакцинопрофилактикаВалеологияВетеринарияГигиенаЗаболеванияИммунологияКардиологияНеврологияНефрологияОнкологияОториноларингологияОфтальмологияПаразитологияПедиатрияПервая помощьПсихиатрияПульмонологияРеанимацияРевматологияСтоматологияТерапияТоксикологияТравматологияУрологияФармакологияФармацевтикаФизиотерапияФтизиатрияХирургияЭндокринологияЭпидемиология

Implementation inheritance in C#

Прочитайте:
  1. Implementation
  2. Implementation
  3. Implementation
  4. Theme: Heredity. Types of inheritance. Independent monogenic inheritance of characteristics
  5. Theme: Heredity. Types of inheritance. Monogenic traits linked inheritance
  6. Theme: Implementation of heriditary information

Def: In object - oriented programming, there are two distinct types of inheritance — implementation inheritance and interface inheritance:

- Implementation inheritance means that a type derives from a base type, taking all the base type ’ s member fields and functions.

Des r: With implementation inheritance, a derived type adopts the base type ’ s implementation of each function, unless it is indicated in the definition of the derived type that a function implementation is to be overridden. This type of inheritance is most useful when you need to add functionality to an existing type, or when a number of related types share a significant amount of common functionality.

Ex:If you want to declare that a class derives from another class, use the following syntax:

class MyDerivedClass: MyBaseClass

{ // functions and data members here}

If a class (or a struct) also derives from interfaces, the list of base class and interfaces is separated by commas:

public class MyDerivedClass: MyBaseClass, IInterface1, IInterface2

{ // etc. }

For a struct, the syntax is as follows:

public struct MyDerivedStruct: IInterface1, IInterface2

{ // etc. }

If you do not specify a base class in a class definition, the C# compiler will assume that System.Object is the base class. Hence, the following two pieces of code yield the same result:

class MyClass // derives from System.Object

{ // etc.}

Because C# supports the object keyword, which serves as a pseudonym for the System.Object class, you can also write:

class MyClass: object // derives from System.Object

{ // etc.}

EX: public class Shape;

{ int x,y;

Public virtual string Draw(string Figure)

{Cons.wr.(Figure);}

}

Class Rectangle: Shape

{ public override string Draw(string Name)

{Cons.Wr(“Rectangle”);}

}

 


Дата добавления: 2015-09-18 | Просмотры: 561 | Нарушение авторских прав



1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |



При использовании материала ссылка на сайт medlec.org обязательна! (0.003 сек.)