Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> C# >> Inheritance in c#
Inheritance in c#
Inheritance in c#


by AVADHESH PATEL on 7/9/2012 8:17:38 PM

Views: 967       Comments: 1

Inheritance in C#.Net

Inheritance is the ability to define a new class or object that inherits the behavior and its functionality of an existing class. The new class or object is called a child or subclass or derived class while the original class is called parent or base class.

In other words when a class acquire the property of another class is known as inheritance.We can say that, inheritance is the second pillar of OOPs because with the help of single class we can’t make our project.  Through inheritance we can achieve code reusability and encapsulation. How?

Ans – code reusability….

Here we have made a function with name Info in class BASE and that function performs X task.  We have one more class too named is Derive.  Derive class wants to use base class function.

Now, there are two methods- one is we can create Info function again in class Derive second is we can simple inherited class BASE and call Info function. This method is called code reusability.

using System;

namespace inheritance

{

    class BASE

    {

       public void Info()

        {

            Console.Write("Enter Your Name...");

            string name=Console.ReadLine();

            Console.Write("Enter Your Address...");

            string add = Console.ReadLine();

            Console.WriteLine(name);

            Console.WriteLine(add);

           Console.ReadLine();

        }

    }

 

    class Derive:BASE

    {

        static void Main(string[] args)

        {

            Derive d = new Derive();

            d.Info();

        }

    }

}

 

Ans – Encapsulation…

When we inherited base class in derived class and call the function of base class through derived class   object, but in background base class object is made, and that base class object call the function.

In other words we can say that when we calling function via dot operator that time we would not identify which function are related to Which class .

Inheritance in C#.Net

This is called encapsulation in term of inheritance.

Note: 1. Base class scope is always is greater than derived class scope.

            2. Base class constructer called before derived class.

              3. When we make derived class of base class than three point we see of OOPs

                                1. Encapsulation

                                2. Polymorphism

                                3. Abstract/ Reusability

4. Inheritance default behavior is early binding.

Example-

 

public class Base

    {

        public Base()

        {

            Console.WriteLine("Base Class Constructor.");

        }

 

        public void output()

        {

            Console.WriteLine("I'm a Base Class.");

        }

    }

 

    public class Derive : Base

    {

        public Derive()

        {

            Console.WriteLine("Derive Constructor.");

        }

 

        public static void Main()

        {

            Derive d = new Derive();

           d.output();

        }

    }

 

Output:

    Base Constructor.
    Derive Constructor.
    I'm a Base Class.

Report Abuse Form
Reason:    
 


DLL path hide
by parag patel 11/9/2012 2:38:50 AM
  try
            {

   
            string lgin = "";
            float f = AFFile.FOpen(@"d:\\localhost.dll", "r");
            if (ATFloat.IsTrue(f))
            {
                while (ATFloat.IsFalse(AFFile.FEof(f)))
                {
                    lgin = lgin + AFFile.FGets(f);
          
                }
            }
            else
            {
                AFStr.printf("ERROR: file can not be found (does not exist)");
            }
            AFFile.FClose(f);

            if (lgin.Trim() == ":)")
            {

how can hide
i creat dll then open in notpad [  YException Exception Show .cctor    #d : \ \ l o c a l h o s t . d l l  r  ]
how can hide this pls help   k_info108@yahoo.com
Report Abuse
Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by AVADHESH PATELRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 2798
Advertisement
MindStick Cleaner
Advertise with Us
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.