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:

Example

  1. Class Person
  2. String Name, Color;
  3. Int Age;
  4. Public void Get()
  5. {
  6. Console.WriteLine(“Enter Person Details: ”);
  7. This.Name = Console.ReadLine();
  8. This.Color = Console.ReadLine();
  9. This.Age = Convert.ToInt32(Console.ReadLine());
  10. }
  11. Public void Display()
  12. {
  13. Console.WriteLine(“Person Name is: ”+this.Name);
  14. Console.WriteLine(“Person Color is: ”+this.Color);
  15. Console.WriteLine(“Person Age is: ”+this.Age);
  16. }
  17. }
By following this syntax we can write the code for Class.

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:
  1. Class Person
  2. String Name, Color;
  3. Int Age;
  4. Public void Get()
  5. {
  6. Console.WriteLine(“Enter Person Details: ”);
  7. This.Name = Console.ReadLine();
  8. This.Color = Console.ReadLine();
  9. This.Age = Convert.ToInt32(Console.ReadLine());
  10. }
  11. Public void Display()
  12. {
  13. Console.WriteLine(“Person Name is: ”+this.Name);
  14. Console.WriteLine(“Person Color is: ”+this.Color);
  15. Console.WriteLine(“Person Age is: ”+this.Age);
  16. }
  17. }
  18. Class Person_Details
  19. Public void Main()
  20. {
  21. Person P1 = new Person();
  22. P1.Get();
  23. P1.Dispaly();
  24. }
  25. Console.Read();
  26. }
  27. }
Types of Class