Object,Class and Inheritance

📘 Object, Class & Inheritance in C#


🔹 Object

Object is basically used to bridge a communication between class body and main body.
Objects are always created inside the main body.


🔹 Syntax

className objName = new className();
objName.function(); // it could be any function inside the class
  • new → new keyword is known as Memory allocation operator

  • dot (.) → Member access operator used to access functions


🔹 Example

class Program
{
    public void display(int a1)
    {
        Console.WriteLine("I am a function ");
    }

    static void Main(string[] args)
    {
        int a;
        Program p1 = new Program();
        p1.display();
        Console.ReadKey();
    }
}

🔹 Class

Class is defined as the collection of data members and member functions.

  • Data members → all the variables inside the class

  • Member functions → all the functions


🔹 Inheritance

Inheritance is the reusability of class.


🔹 Types of Classes

  1. Base Class (top class of the program)

  2. Derived Class


🔹 Rules of Inheritance

  1. Derived class accesses information to base class

  2. Base class cannot access information to derived class

  3. Always last class's object is created (important)


Comments

Popular posts from this blog

Introduction To HTML

Data Binding Functions

Export GridView to Excel