SlideShare a Scribd company logo
1 of 29
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
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
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
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
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
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
_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

What's hot

Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
Doncho Minkov
 

What's hot (20)

Oracle Forms : Transnational Triggers
Oracle Forms : Transnational TriggersOracle Forms : Transnational Triggers
Oracle Forms : Transnational Triggers
 
SQL Interview Questions - InterviewBit.pdf
SQL Interview Questions - InterviewBit.pdfSQL Interview Questions - InterviewBit.pdf
SQL Interview Questions - InterviewBit.pdf
 
Skillwise JCL
Skillwise JCLSkillwise JCL
Skillwise JCL
 
T-SQL Overview
T-SQL OverviewT-SQL Overview
T-SQL Overview
 
Chapter 2 c#
Chapter 2 c#Chapter 2 c#
Chapter 2 c#
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
05 Creating Stored Procedures
05 Creating Stored Procedures05 Creating Stored Procedures
05 Creating Stored Procedures
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
C# in depth
C# in depthC# in depth
C# in depth
 
Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013
 
Introduction to Simplified instruction computer or SIC/XE
Introduction to Simplified instruction computer or SIC/XEIntroduction to Simplified instruction computer or SIC/XE
Introduction to Simplified instruction computer or SIC/XE
 
Packages - PL/SQL
Packages - PL/SQLPackages - PL/SQL
Packages - PL/SQL
 
Android Connecting to Internet
Android Connecting to InternetAndroid Connecting to Internet
Android Connecting to Internet
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
 
Code optimization
Code optimizationCode optimization
Code optimization
 
PART-2 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-2 : Mastering RTOS FreeRTOS and STM32Fx with DebuggingPART-2 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-2 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
 

Viewers also liked

Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 

Viewers also liked (20)

Key concept
Key conceptKey concept
Key concept
 
Unit 1 concept world.
Unit 1 concept world.Unit 1 concept world.
Unit 1 concept world.
 
C++ Programming Chapter 01
C++ Programming Chapter 01C++ Programming Chapter 01
C++ Programming Chapter 01
 
C++ chapter 1
C++ chapter 1C++ chapter 1
C++ chapter 1
 
Application of Stacks
Application of StacksApplication of Stacks
Application of Stacks
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Stack Applications
Stack ApplicationsStack Applications
Stack Applications
 
polymorphism
polymorphism polymorphism
polymorphism
 
Stack
StackStack
Stack
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Object-Oriented Programming Concepts
Object-Oriented Programming ConceptsObject-Oriented Programming Concepts
Object-Oriented Programming Concepts
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
 
Object oriented programming (oop) cs304 power point slides lecture 01
Object oriented programming (oop)   cs304 power point slides lecture 01Object oriented programming (oop)   cs304 power point slides lecture 01
Object oriented programming (oop) cs304 power point slides lecture 01
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 

Similar to Classes and objects

New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
rashmita_mishra
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
mwillmer
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
nirajmandaliya
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
Abed Bukhari
 

Similar to Classes and objects (20)

C#2
C#2C#2
C#2
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
C questions
C questionsC questions
C questions
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
Clean code
Clean codeClean code
Clean code
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
 
-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptx-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptx
 
-Kotlin Camp Unit2.pptx
-Kotlin Camp Unit2.pptx-Kotlin Camp Unit2.pptx
-Kotlin Camp Unit2.pptx
 

More from Bhushan Mulmule

More from Bhushan Mulmule (14)

Implementing auto complete using JQuery
Implementing auto complete using JQueryImplementing auto complete using JQuery
Implementing auto complete using JQuery
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3
 
Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1
 
NInject - DI Container
NInject - DI ContainerNInject - DI Container
NInject - DI Container
 
Dependency injection for beginners
Dependency injection for beginnersDependency injection for beginners
Dependency injection for beginners
 
Understanding Interfaces
Understanding InterfacesUnderstanding Interfaces
Understanding Interfaces
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Inheritance
InheritanceInheritance
Inheritance
 
Methods
MethodsMethods
Methods
 
Getting started with C# Programming
Getting started with C# ProgrammingGetting started with C# Programming
Getting started with C# Programming
 
Overview of .Net Framework 4.5
Overview of .Net Framework 4.5Overview of .Net Framework 4.5
Overview of .Net Framework 4.5
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Classes and objects