Home > C# > C# Inheritance

C# Inheritance


class A
    int aVariable;
    public A()
    public void SomeMethodA()
class B : A
    int bVariable;
    public B()
    public void SomeMethodB()

B inherits from A or in other words B extends A.

C# supports single inheritance, a class can inherit from only one class. But a class can inherit multiple interfaces.

In above example, B inherits variableA and SomeMethodA also it adds bVariable and SomeMethodB.

Constructors are not inherited.

Inherited methods can be overridden.

A class can inherit only from another class not struct.

A class without explicit base class inherits from class Object.

Categories: C#
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: