Skip to main content

Posts

Showing posts with the label C# for Beginners

Simple Object Oriented Programming (OOP) Concepts with Examples Part 1

Let's begin with a simple base class and derived class, and explain how the both are working. Let's create a Base Class with the constructor taking no parameters,         class BaseClass1         {             public BaseClass1()             {                 Console .WriteLine( "In BaseClass1 constructor" );             }         }    And Creating a Derived Class DerivedClass1   which inherits Base class BaseClass1           class DerivedClass1 : BaseClass1         {             public DerivedClass1()             {                 Console .WriteLine( "In DerivedClass1 constructor" );             }         } And in the Main Function just create an object for the BaseClass1              BaseClass1 BC1Obj = new BaseClass1 (); Now the output will be                 In BaseClass1 constructor While trying to create another object for                 BaseClass1 BC1Obj2 = new DerivedClass1 (); Now the output will be