Class
Class is a blueprint about object that provide an overview of object, as we know that oops consider each and everything as Entity.
Let us consider Person, Person is a class that contain Colors, Height, Age and more as well as Method of Person is Playing, Eating and more.
A person could be me, you and any one which will contain member variable as colors, height, age and method as playing, eating and more.
Syntax for creating class is:
Class ClassName
{
Member variable
Method()
{
Member Decalaration
}
Method()
{
Implementation
}
}
Example
- Class Person
- String Name, Color;
- Int Age;
- Public void Get()
- {
- Console.WriteLine(“Enter Person Details: ”);
- This.Name = Console.ReadLine();
- This.Color = Console.ReadLine();
- This.Age = Convert.ToInt32(Console.ReadLine());
- }
- Public void Display()
- {
- Console.WriteLine(“Person Name is: ”+this.Name);
- Console.WriteLine(“Person Color is: ”+this.Color);
- Console.WriteLine(“Person Age is: ”+this.Age);
- }
- }
Object
Object is instance value of Class. Constructor get automatically invoked when object of class gets created. For creating object, class is mandatory. The syntax for creating object is:
Class Name object=new Class Name()
Example for creating object and implementing it:
- Class Person
- String Name, Color;
- Int Age;
- Public void Get()
- {
- Console.WriteLine(“Enter Person Details: ”);
- This.Name = Console.ReadLine();
- This.Color = Console.ReadLine();
- This.Age = Convert.ToInt32(Console.ReadLine());
- }
- Public void Display()
- {
- Console.WriteLine(“Person Name is: ”+this.Name);
- Console.WriteLine(“Person Color is: ”+this.Color);
- Console.WriteLine(“Person Age is: ”+this.Age);
- }
- }
- Class Person_Details
- Public void Main()
- {
- Person P1 = new Person();
- P1.Get();
- P1.Dispaly();
- }
- Console.Read();
- }
- }

Join the conversation! Your thoughts help the community grow.