Hello Friends,
Now I am going to describe anather OOP concept of
C# dotnet.Generally Abstraction is a concept through which we can see only
assential part of the object ,we can't see the background details or inner part
of the object.
If we will see the real world example than this
concept will be cleared.when we are watching TV then through our Remote we
controls any operations means we can move one chanel to anather chanel to enjoy
different programs that can be news,songs and serial etc.
But matter is that when we are enjoying any program
in TV at that time we don't try to see any background part of TV like picture
tube,circute,electronics chips etc and we donot know about it's internal process
or how it work.
Finally we can say that it is a concept through
which the essential part of the object will represented hiding the background
detail.It leads to data hiding and data hiding leads to data security.
Ex:
Abstract Class:
Abstract class is a type of class
whose data member and member function can be accessed in derived class.The
members of abstract class can be private as well as protected.It is define by
abstract key word.
Ex:
using System;
namespace abstractclass
{
abstract class abstractprog
{
namespace abstractclass
{
abstract class abstractprog
{
//Non abstract method
public void myabstractprog(string s)
{
Console.WriteLine (s.Length);
}
//abstract method
public abstract void myabstract(int i, int j);
public static void Main(string[] args)
{
mainclass obj = new mainclass();
obj.myabstractprog("rabi");
obj.myabstract(10,20);
}
}
class mainclass:abstractprog
{
public override void myabstract(int i, int j)
{
Console.WriteLine (i*j);
}
}
}
public void myabstractprog(string s)
{
Console.WriteLine (s.Length);
}
//abstract method
public abstract void myabstract(int i, int j);
public static void Main(string[] args)
{
mainclass obj = new mainclass();
obj.myabstractprog("rabi");
obj.myabstract(10,20);
}
}
class mainclass:abstractprog
{
public override void myabstract(int i, int j)
{
Console.WriteLine (i*j);
}
}
}
OutPut:
4
200
Thanks & Regard
Rabi
No comments:
Post a Comment