Abstract Access Modifier

Posted on Updated on

Image result for Abstract Access Modifier in dot netAbstract Access Modifier

The general meaning of abstract is “existing in thought or as an idea but not having a physical or concrete existence.” The abstract modifier is one of the important access modifier of object oriented language. This modifier shows that the the code on which we are implementing abstract has missing or incomplete implementation. These modifier can be used with classes, methods, properties, indexers and events.

The abstract classess are marked with the keyword abstract and are basically used to define the base classes. The abstract classes are also known as incomplete classes as instance of the abstract classes can’t be created. The members of the abstract classes or that are marked with abstract keyword must be implemented by the classes that inherit these abstract classes.

Features of abstract classes

1) It is not possible to create the object of the abstract class.
2) Abstract can have abstract methods and accessors.
3) An abstract class can’t be a sealed class.
4) A derived class which is inheriting the abstract class must implement all the inherited members of the abstract base class.

Features of abstract methods

1) A method which is declared as abstract is implicitly a virtual method.
2) Abstract methods can only be declared in the abstract classes.
3) Abstract methods donot have any actual implementation i.e. they have no method body.
4) We cannot use static or virtual keyword, if done so will generate an error.

Features of abstract properties

Abstract properties are just like abstract methods, the only difference lies in the declaration and invocation of the syntax.
1) Abstract modifier can’t be used with the static property.
2) It is possible to override the abstract property in a derived class using override modifier.

abstract class BaseClass // Abstract class
{
protected int _x = 100;
protected int _y = 150;
public abstract void AbstractMethod(); // Abstract method
public abstract int X { get; }
public abstract int Y { get; }
}

class DerivedClass : BaseClass
{
public override void AbstractMethod()
{
_x++;
_y++;
}

public override int X // overriding property
{
get
{
return _x + 10;
}
}

public override int Y // overriding property
{
get
{
return _y + 10;
}
}

static void Main()
{
DerivedClass o = new DerivedClass();
o.AbstractMethod();
Console.WriteLine(“x = {0}, y = {1}”, o.X, o.Y);
}
}
// Output: x = 111, y = 161

*****************************************************************************************************

For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.
Helpline: 9814666333, 8699444666
Email: info@technocampus.co.in

Please fill the form and we shall contact you soon.

 

Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s