Inheritance Model in C#
Before Understanding the inheritance we should know ,why inheritance we need,
without inheritance ,
now look the concept, i am using using two classes Name A ,B And taking function and i want to acess this function using Class B objects ,Then
class A
{
fun1()
{
console.writeline("hai");
}
}
class B
{
A a=new A();
}
public void main()
{
B b=new B();
b.a.fun1();
}
ans-hai
here , we see In class B we create the object of class A , and then in main finction we create object of class B and using B's object we call class A's function so we get our goal , but here we see , we have to create inner object of Class A in Class B, in this way we need to create always inner object to call base class members and functions so,its a tired work,
Inheritance- inheritance is the mechanism in which sub class inherits the properties of base class.
so we can say in ,other words ,inheritance maintain the containership and encapsulation and maintains abstraction ,in which child the get the properties of base class automatically .
.. this is the main diffrence in without inheritance and inheritance .
polymorphism- continue...
Before Understanding the inheritance we should know ,why inheritance we need,
without inheritance ,
now look the concept, i am using using two classes Name A ,B And taking function and i want to acess this function using Class B objects ,Then
class A
{
fun1()
{
console.writeline("hai");
}
}
class B
{
A a=new A();
}
public void main()
{
B b=new B();
b.a.fun1();
}
ans-hai
here , we see In class B we create the object of class A , and then in main finction we create object of class B and using B's object we call class A's function so we get our goal , but here we see , we have to create inner object of Class A in Class B, in this way we need to create always inner object to call base class members and functions so,its a tired work,
Inheritance- inheritance is the mechanism in which sub class inherits the properties of base class.
so we can say in ,other words ,inheritance maintain the containership and encapsulation and maintains abstraction ,in which child the get the properties of base class automatically .
.. this is the main diffrence in without inheritance and inheritance .
polymorphism- continue...
No comments:
Post a Comment