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
Base Class (top class of the program)
Derived Class
🔹 Rules of Inheritance
Derived class accesses information to base class
Base class cannot access information to derived class
Always last class's object is created (important)
Comments
Post a Comment