SlideShare a Scribd company logo
Classes and Objects
Bhushan Mulmule
bhushan.mulmule@dotnetvideotutorial.com
www.dotnetvideotutorial.com
For video visit
www.dotnetvideotutorial.com
Agenda
Need of
Object
Orientation
Classes and
Objects
Constructor Properties
Automatic
Properties
Destructor
www.dotnetvideotutorial.com
Need of Object
Orientation
static void Main(string[] args)
{
int empNo;
string name;
float basicSalary, hra, da, pf, grossSalary;
...
...
}
Real world Digital world
empNo Name basicSalary
hra da pf grossSalary
www.dotnetvideotutorial.com
Real world Digital world
struct Employee
{
int empNo;
string name;
float basicSalary, hra, da, pf, grossSalary;
}
static void Main()
{
Employee emp;
}
empNo name basic
Salary
hra da pf gross
Salary
emp
www.dotnetvideotutorial.com
Real world Digital world
class Employee
{
public int empNo;
public string name;
public float basicSalary, hra, da, pf, grossSalary;
public void CalculateSalary()
{
hra = 15 * basicSalary / 100;
da = 10 * basicSalary / 100;
pf = 5 * basicSalary / 100;
grossSalary = basicSalary + hra + da - pf;
}
}
class Program
{
static void Main()
{
Employee emp = new Employee();
}
}
empNo name basic
Salary
hra da pf gross
Salary
emp
www.dotnetvideotutorial.com
Classes and objects
www.dotnetvideotutorial.com
e2
3000
_empNo _name _salary
e1
2000
2000
3000
Main
Program
Employee
this
30002000
_empNo _name _salary
Heap
Class
 A class is a construct that enables you to create your own custom types by
grouping together variables of other types, methods and events.
 A class is like a blueprint. It defines the data and behavior of a type.
 Client code can use it by creating objects or instances which are assigned to a
variable.
www.dotnetvideotutorial.com
Object
 An object is a block of memory that has been allocated and configured
according to the blueprint (typically class).
 A program may create many objects of the same class.
 Objects can be stored in either a named variable or in an array or collection.
 Client code is the code that uses these variables to call the methods and access
the public properties of the object.
 In an object-oriented language such as C#, a typical program consists of multiple
objects interacting dynamically.
www.dotnetvideotutorial.com
Constructors
www.dotnetvideotutorial.com
Constructor
 Constructors are special methods with the same name as of class
 Typically used to initialize the data members of the new object.
 Invoked by the new operator immediately after memory is allocated for the new
object.
 Class can have multiple constructors that take different arguments (overloading)
 Constructor that takes no parameters is called a default constructor.
 If no constructor is provided, C# creates one by default.
www.dotnetvideotutorial.com
Classes and objects
www.dotnetvideotutorial.com
e2
3000
_empNo _name _salary
e1
2000
2000
3000
Main
Program
Employeethis
3000
_empNo _name _salary
(int empno, string name, float salary)
Employee
Properties
www.dotnetvideotutorial.com
Properties
 A property is a member that provides a flexible mechanism to read, write, or
compute the value of a private field.
 Properties can be used as if they are public data members, but they are actually
special methods called accessors.
 This enables data to be accessed easily and still helps promote the safety and
flexibility of methods.
 A get property accessor is used to return the property value, and a set accessor
is used to assign a new value. These accessors can have different access levels.
 Properties that do not implement a set accessor are read only.
www.dotnetvideotutorial.com
Classes and objects
www.dotnetvideotutorial.com
e2
3000
_empNo _name _salary
e1
2000
2000
3000
Main
Program
Employeethis
30002000
_empNo _name _salary
EmpNo
value
get
set
Automatic Properties
 Improves readability
 Reduces coding efforts
 Are useful when validation and calculations are not required in properties.
www.dotnetvideotutorial.com
public int EmpNo { get; set; }
private int _EmpNo;
public int EmpNo
{
get
{ return this._EmpNo; }
set
{ this._EmpNo = value; }
}
Compiler converts into
Classes and objects
Destructor
www.dotnetvideotutorial.com
Destructor
 Destructor is special method with same name as of class name prefixed by tilde (~)
 A class can only have one destructor.
 Destructors cannot be inherited or overloaded.
 Destructors cannot be called. They are invoked automatically by garbage collector just
before destroying the object (if provided).
 A destructor does not take modifiers or have parameters.
 Destructors are also called when the program exits.
 Can be used to write clean up code such as releasing unmanaged resources (if used in
class)
www.dotnetvideotutorial.com
Classes and objects
e2
3000
_empNo _name _salarye1
2000
2000
3000
Main
Program
_empNo _name _salary
fun1
Object
Life
Cycle
Memory
Allocation
Constructor
UseDestructor
Memory
Deallocation
(by Garbage
Collector)
www.dotnetvideotutorial.com
Classes and objects
_empNo _name _basic
Salary
_hra _da _pf _gross
Salary
e2
3000
_empNo _name _basic
Salary
_hra _da _pf _gross
Salary
e1
2000
2000
3000
Main
Program
Employee
this
30002000
Bhushan Mulmule
bhushan.mulmule@dotnetvideotutorial.com
www.dotnetvideotutorial.com

More Related Content

PDF
Querydsl overview 2014
PPTX
Key concept
PPTX
Unit 1 concept world.
PPT
C++ Programming Chapter 01
PDF
C++ chapter 1
PPT
Application of Stacks
PPT
Lecture 2
PDF
Applications of stack
Querydsl overview 2014
Key concept
Unit 1 concept world.
C++ Programming Chapter 01
C++ chapter 1
Application of Stacks
Lecture 2
Applications of stack

Viewers also liked (13)

PPTX
polymorphism
PPSX
PDF
Polymorphism
PPT
Object-Oriented Programming Concepts
PPTX
Polymorphism
PPTX
STACKS IN DATASTRUCTURE
PPT
Basic concepts of object oriented programming
PPT
Object oriented programming (oop) cs304 power point slides lecture 01
PPTX
Introduction to Object Oriented Programming
PPT
Object-oriented concepts
PPT
Oops ppt
PPT
Object Oriented Programming Concepts
polymorphism
Polymorphism
Object-Oriented Programming Concepts
Polymorphism
STACKS IN DATASTRUCTURE
Basic concepts of object oriented programming
Object oriented programming (oop) cs304 power point slides lecture 01
Introduction to Object Oriented Programming
Object-oriented concepts
Oops ppt
Object Oriented Programming Concepts
Ad

Similar to Classes and objects (20)

DOCX
New microsoft office word document (2)
ODP
Bring the fun back to java
DOCX
C questions
PDF
Javascript Design Patterns
PDF
Dart for Java Developers
PDF
Uncommon Design Patterns
PPT
Object Oriented Programming Concept.Hello
PPT
C++ classes tutorials
PDF
.NET Portfolio
PPSX
Object oriented concepts & programming (2620003)
PDF
Intake 38 data access 5
PPTX
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
PDF
C++ Interview Questions and Answers PDF By ScholarHat
PDF
C++ Object oriented concepts & programming
PPT
Oops concepts in php
PDF
Object Oriented Programming (OOP) using C++ - Lecture 1
PDF
Clean code
PPTX
OOC MODULE1.pptx
PPTX
CPP Homework Help
New microsoft office word document (2)
Bring the fun back to java
C questions
Javascript Design Patterns
Dart for Java Developers
Uncommon Design Patterns
Object Oriented Programming Concept.Hello
C++ classes tutorials
.NET Portfolio
Object oriented concepts & programming (2620003)
Intake 38 data access 5
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
C++ Interview Questions and Answers PDF By ScholarHat
C++ Object oriented concepts & programming
Oops concepts in php
Object Oriented Programming (OOP) using C++ - Lecture 1
Clean code
OOC MODULE1.pptx
CPP Homework Help
Ad

More from Bhushan Mulmule (16)

PDF
Implementing auto complete using JQuery
PDF
Windows Forms For Beginners Part 5
PDF
Windows Forms For Beginners Part - 4
PDF
Windows Forms For Beginners Part - 3
PDF
Windows Forms For Beginners Part - 2
PDF
Windows Forms For Beginners Part - 1
PDF
NInject - DI Container
PDF
Dependency injection for beginners
PPTX
Understanding Interfaces
PPTX
Polymorphism
PPTX
Inheritance
PPTX
PPTX
Arrays, Structures And Enums
PPTX
Flow Control (C#)
PPTX
Getting started with C# Programming
PPTX
Overview of .Net Framework 4.5
Implementing auto complete using JQuery
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 1
NInject - DI Container
Dependency injection for beginners
Understanding Interfaces
Polymorphism
Inheritance
Arrays, Structures And Enums
Flow Control (C#)
Getting started with C# Programming
Overview of .Net Framework 4.5

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
KodekX | Application Modernization Development
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Spectroscopy.pptx food analysis technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
Teaching material agriculture food technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Electronic commerce courselecture one. Pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
sap open course for s4hana steps from ECC to s4
KodekX | Application Modernization Development
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
cuic standard and advanced reporting.pdf
Spectral efficient network and resource selection model in 5G networks
MIND Revenue Release Quarter 2 2025 Press Release
Spectroscopy.pptx food analysis technology
Dropbox Q2 2025 Financial Results & Investor Presentation
Advanced methodologies resolving dimensionality complications for autism neur...
Teaching material agriculture food technology
MYSQL Presentation for SQL database connectivity
Per capita expenditure prediction using model stacking based on satellite ima...
Electronic commerce courselecture one. Pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Chapter 3 Spatial Domain Image Processing.pdf
Network Security Unit 5.pdf for BCA BBA.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx

Classes and objects