Skip to main content

Posts

Inheritance in c#

Inheritance is one of the pillars of Object Oriented Programming. It allows the child class to reuse, extend and modify the behavior of parent class. The class whose members are inherited is called as base class and class who inherits is called a derived class. We can inherit only one class at a time. Multiple inheritance is not supported in c#. A struct cannot inherit any base class doing so will generate a compiler error. 1.       Private members are only accessible to the derived class which is nested in the inherited base class. 2.       Protected members are accessible only in derived class. 3.       Internal members are accessible in the derived class that is visible in the same assembly of the base class. 4.       Public members are accessible in the derived class. They can be called just as if they were declared in the derived class. All Types are implicitly inherited ...

Static Keyword in c#

What can be static in c#? Class, fields, methods, properties, operators, events, and constructors. Static keyword cannot be used with indexers, finalizers, or types other than classes. Static Class: 1.        If a class is declared static it can only contain static members the reason for this is the class cannot be instantiated in short it is sealed. 2.        The instance of every non-static class contains a separate copy of instance class fields while a static class will have an only single copy of the fields. 3.         A static class cannot have a constructor but it can contain static constructor without any access modifiers.    public static class Employee     {         //Static contructor         static Employee()       ...

Session 4:- Constructor in c#

Date Wednesday, December 04, 2013 Time Description 10.00 am to 12.00 pm Constructor, Destructor, Inheritance, Constructor in inheritance Learning : It is same as that of function but difference is that it does not have any return type.             Its name is same as that of the class, it cannot be inherited. Constructor of a class is expected when object of the class is created usually we put initialisation code in the constructor. Eg. Public class myclass {    Public myclass()   {      //constructor body or initialisation code   } } C # supports constructor overloading, i.e we can have constructor with different set of parameter for same class Eg.  1: Public class myclass 2: { 3: Public myclass() 4: { 5: //default constructor 6: } 7: Public myclass(int a, int b) 8: ...