How oops concepts is implemented in the Asp.Net
Posted by User: Sneha SharmaQuestion:
I need a brief details about the opps concepts implemented in the Asp.Net .Though multiple inheritance is not supported in C# How can we inherit from one master page to many aspx pages.
Ans:
Multiple inheritance means one class is derived from multiple classes, which is not possible in case of c#. Which can be achieved using interface.
Ex: Here how master page and child page uses oops concepts...Many individual child classes (child class) are derived from only one master page. (Parent class)
ChildPage1: Masterpage1
Real Time Example:
Here we have derived two child classes (About, Default child pages) from one parent class (Page class - master page)
Partial class About
Inherits Page
End Class
Partial class Default
Inherits Page
End Class
here we are not deriving one child page (child class) from many master pages (Parent classes)
For Ex:
Childpage1: MasterPage1, MasterPage2
Hope this will clear your doubts. Let me know if any questions...
Its a great source for developer
ReplyDeleteThank you @Sneha sharma.
DeleteIf you like our answers, you can subscribe to my blog, by submitting your email id.
Regards,
Jatin Nahar
Hi Jatin is correct,
ReplyDeleteHowever some times Partial classes can also be good choice.
C# program that uses partial class
class Program
{
static void Main()
{
A.A1();
A.A2();
}
}
Contents of file A1.cs: C#
using System;
partial class A
{
public static void A1()
{
Console.WriteLine("A1");
}
}
Contents of file A2.cs: C#
using System;
partial class A
{
public static void A2()
{
Console.WriteLine("A2");
}
}
Output
A1
A2