What is Class With Example Code

A class in programming is a blueprint or template for creating objects
instances. It defines the structure and behavior of objects of a particular type.
Classes encapsulate data attributes or properties and
Behaviors methods or functions that operate on that data.



using System;
 
namespace ConsoleApp1
{
    // Define a class named "Employee"
    public class Employee
    {
        // Fields (attributes) with modified names
        public string FullName; // Changed from "Name"
        public int EmployeeAge; // Changed from "Age"
 
        // Constructor (initializer)
        public Employee(string fullName, int employeeAge)
        {
            FullName = fullName;
            EmployeeAge = employeeAge;
        }
 
        // Method (behavior)
        public void Introduce()
        {
            Console.WriteLine($"Hi, my name is {FullName}, and I'm {EmployeeAge} years old.");
        }
    }
 
    class Program
    {
        static void Main(string[] args)
        {
            // Create an object (instance) of the Employee class
            Employee employee1 = new Employee("A", 30);
            // Accessing object's properties and methods
            Console.WriteLine($"Full Name: {employee1.FullName}, Age: {employee1.EmployeeAge}");
            employee1.Introduce(); // Output: Hi, my name is John, and I'm 30 years old.
 
        }
    }
}