SlideShare a Scribd company logo
1 of 27
Car beetle = new Car();
Object Creation - Behind the scenes
{CHEEZYCODE}
Car beetle = new Car();
class Car
{
//Properties
public int modelYear;
public string carName;
public string carType;
public float price;
//Methods
public void DriveCar()
{
Console.WriteLine("Car is driving");
}
public void ApplyBrake()
{
Console.WriteLine("Car is applying brakes");
}
}
{CHEEZYCODE}
Car beetle = new Car(); 1
class Car
{
//Properties
public int modelYear;
public string carName;
public string carType;
public float price;
//Methods
public void DriveCar()
{
Console.WriteLine("Car is driving");
}
public void ApplyBrake()
{
Console.WriteLine("Car is applying brakes");
}
} {CHEEZYCODE}
Car beetle = new Car(); 1 When we say new Car(), new
object in the memory is created.
class Car
{
//Properties
public int modelYear;
public string carName;
public string carType;
public float price;
//Methods
public void DriveCar()
{
Console.WriteLine("Car is driving");
}
public void ApplyBrake()
{
Console.WriteLine("Car is applying brakes");
}
}
{CHEEZYCODE}
Car beetle = new Car(); 1 When we say new Car(), new
object in the memory is created.
Memory Locations
{CHEEZYCODE}
Car beetle = new Car(); 1 When we say new Car(), new
object in the memory is created.
Object will occupy certain
bytes in memory
Memory Locations
{CHEEZYCODE}
Car beetle = new Car(); 1 When we say new Car(), new
object in the memory is created.
Memory Locations
{CHEEZYCODE}
Car beetle = new Car(); 1 When we say new Car(), new
object in the memory is created.
Memory Locations
{CHEEZYCODE}
Car beetle = new Car(); 1 When we say new Car(), new
object in the memory is created.
This is new object of
Car in memory
Memory Locations
{CHEEZYCODE}
Car beetle = new Car(); 2
This is new object of
Car in memory
Memory Locations
Object has been created, now
location of this object is passed
as a reference
{CHEEZYCODE}
Car beetle = new Car(); 3
This is new object of
Car in memory
Memory Locations
Location of this object is stored in
beetle to access the car object
{CHEEZYCODE}
Car beetle = new Car(); 4
beetle
Memory Locations
Now you can access newly created
object in memory with the help of
beetle reference
{CHEEZYCODE}
Car beetle = new Car(); 5
beetle
What does this object has?
{CHEEZYCODE}
Car beetle = new Car(); 5
beetle
What does this object has?
class Car
{
//Properties
public int modelYear;
public string carName;
public string carType;
public float price;
//Methods
public void DriveCar()
{
Console.WriteLine("Car is driving");
}
public void ApplyBrake()
{
Console.WriteLine("Car is applying brakes");
}
}
Remember this ?
{CHEEZYCODE}
Car beetle = new Car(); 6
beetle
Object stores properties values - it
could be another object or built in
types like int or float
class Car
{
//Properties
public int modelYear;
public string carName;
public string carType;
public float price;
//Methods
public void DriveCar()
{
Console.WriteLine("Car is driving");
}
public void ApplyBrake()
{
Console.WriteLine("Car is applying brakes");
}
} {CHEEZYCODE}
7beetle beetle object in memory has
these properties
class Car
{
//Properties
public int modelYear;
public string carName;
public string carType;
public float price;
//Methods
public void DriveCar()
{
Console.WriteLine("Car is driving");
}
public void ApplyBrake()
{
Console.WriteLine("Car is applying brakes");
}
}
modelYear (Integer)
carName (String)
carType(String)
price(float)
{CHEEZYCODE}
8 What if I want to create 2 objects?
{CHEEZYCODE}
8 What if I want to create 2 objects?
Car beetle = new Car();
Car mustang = new Car();
{CHEEZYCODE}
8 What if I want to create 2 objects?
Car beetle = new Car();
Car mustang = new Car();
Same process will be followed
{CHEEZYCODE}
8 What if I want to create 2 objects?
modelYear (Integer)
carName (String)
carType(String)
price(float)
modelYear (Integer)
carName (String)
carType(String)
price(float)
beetle mustang
{CHEEZYCODE}
8
beetle
What if I want to create 2 objects?
modelYear (Integer)
carName (String)
carType(String)
price(float)
modelYear (Integer)
carName (String)
carType(String)
price(float)
mustang
BOTH
OBJECTS
ARE
DIFFERENT
{CHEEZYCODE}
9
Assign values to these properties
using dot(.) operator
beetle
modelYear (Integer)
carName (String)
carType(String)
price(float)
Assigning values to
these properties.
These are similar to
variables but they are
inside beetle and part of
beetle object.
{CHEEZYCODE}
9
Assign values to these properties
using dot(.) operator
beetle
modelYear (Integer)
carName (String)
carType(String)
price(float)
beetle.modelYear = 2017;
beetle.carName = "Volkswagen Beetle“;
beetle.carType = "Beetle 1.8T “;
beetle.price = 19795F;
{CHEEZYCODE}
10
Access these properties using dot
operator
beetle
modelYear (Integer)
carName (String)
carType(String)
price(float)
You access the
properties of beetle
using dot operator
{CHEEZYCODE}
10
Assign values to these properties
using dot(.) operator
beetle
modelYear (Integer)
carName (String)
carType(String)
price(float)
Console.WriteLine(beetle.modelYear);
and similarly you access other
properties of object
{CHEEZYCODE}
Classes And Objects
This is how it works behind the scenes
{CHEEZYCODE}
{CHEEZYCODE}
WE ARE SOCIAL
SUBSCRIBE

More Related Content

Similar to Classes and Objects In C# With Example

14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classesIntro C# Book
 
For the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfFor the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfarjunhassan8
 
C#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfC#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfajantha11
 
(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_ii(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_iiNico Ludwig
 
I need to do the followingAdd a new item to the inventory m.pdf
I need to do the followingAdd a new item to the inventory m.pdfI need to do the followingAdd a new item to the inventory m.pdf
I need to do the followingAdd a new item to the inventory m.pdfadianantsolutions
 
This is my visual studio C code how do I make it so that w.pdf
This is my visual studio C code how do I make it so that w.pdfThis is my visual studio C code how do I make it so that w.pdf
This is my visual studio C code how do I make it so that w.pdfadinathfashion1
 
Create a system to simulate vehicles at an intersection. Assume th.pdf
Create a system to simulate vehicles at an intersection. Assume th.pdfCreate a system to simulate vehicles at an intersection. Assume th.pdf
Create a system to simulate vehicles at an intersection. Assume th.pdfarchanacomputers1
 
Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)Sameer Rathoud
 
(5) c sharp introduction_object_orientation_part_ii
(5) c sharp introduction_object_orientation_part_ii(5) c sharp introduction_object_orientation_part_ii
(5) c sharp introduction_object_orientation_part_iiNico Ludwig
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftOleksandr Stepanov
 
#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docxmayank272369
 
In C#, visual studio, I want no more text boxes added, I have button.pdf
In C#, visual studio, I want no more text boxes added, I have button.pdfIn C#, visual studio, I want no more text boxes added, I have button.pdf
In C#, visual studio, I want no more text boxes added, I have button.pdfaggarwalenterprisesf
 
Public class race track {public static void main(string[] args
Public class race track {public static void main(string[] argsPublic class race track {public static void main(string[] args
Public class race track {public static void main(string[] argsYASHU40
 
Goal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdfGoal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdfarsmobiles
 

Similar to Classes and Objects In C# With Example (20)

14. Java defining classes
14. Java defining classes14. Java defining classes
14. Java defining classes
 
For the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfFor the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdf
 
OOP and C++Classes
OOP and C++ClassesOOP and C++Classes
OOP and C++Classes
 
C#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfC#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdf
 
(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_ii(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_ii
 
I need to do the followingAdd a new item to the inventory m.pdf
I need to do the followingAdd a new item to the inventory m.pdfI need to do the followingAdd a new item to the inventory m.pdf
I need to do the followingAdd a new item to the inventory m.pdf
 
Optional in Java 8
Optional in Java 8Optional in Java 8
Optional in Java 8
 
This is my visual studio C code how do I make it so that w.pdf
This is my visual studio C code how do I make it so that w.pdfThis is my visual studio C code how do I make it so that w.pdf
This is my visual studio C code how do I make it so that w.pdf
 
C# Programming Help
C# Programming HelpC# Programming Help
C# Programming Help
 
JavaScript Core
JavaScript CoreJavaScript Core
JavaScript Core
 
Create a system to simulate vehicles at an intersection. Assume th.pdf
Create a system to simulate vehicles at an intersection. Assume th.pdfCreate a system to simulate vehicles at an intersection. Assume th.pdf
Create a system to simulate vehicles at an intersection. Assume th.pdf
 
Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)
 
Unit4_2.pdf
Unit4_2.pdfUnit4_2.pdf
Unit4_2.pdf
 
(5) c sharp introduction_object_orientation_part_ii
(5) c sharp introduction_object_orientation_part_ii(5) c sharp introduction_object_orientation_part_ii
(5) c sharp introduction_object_orientation_part_ii
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift
 
Java doc Pr ITM2
Java doc Pr ITM2Java doc Pr ITM2
Java doc Pr ITM2
 
#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx
 
In C#, visual studio, I want no more text boxes added, I have button.pdf
In C#, visual studio, I want no more text boxes added, I have button.pdfIn C#, visual studio, I want no more text boxes added, I have button.pdf
In C#, visual studio, I want no more text boxes added, I have button.pdf
 
Public class race track {public static void main(string[] args
Public class race track {public static void main(string[] argsPublic class race track {public static void main(string[] args
Public class race track {public static void main(string[] args
 
Goal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdfGoal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdf
 

Recently uploaded

办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 

Recently uploaded (20)

办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 

Classes and Objects In C# With Example

  • 1. Car beetle = new Car(); Object Creation - Behind the scenes {CHEEZYCODE}
  • 2. Car beetle = new Car(); class Car { //Properties public int modelYear; public string carName; public string carType; public float price; //Methods public void DriveCar() { Console.WriteLine("Car is driving"); } public void ApplyBrake() { Console.WriteLine("Car is applying brakes"); } } {CHEEZYCODE}
  • 3. Car beetle = new Car(); 1 class Car { //Properties public int modelYear; public string carName; public string carType; public float price; //Methods public void DriveCar() { Console.WriteLine("Car is driving"); } public void ApplyBrake() { Console.WriteLine("Car is applying brakes"); } } {CHEEZYCODE}
  • 4. Car beetle = new Car(); 1 When we say new Car(), new object in the memory is created. class Car { //Properties public int modelYear; public string carName; public string carType; public float price; //Methods public void DriveCar() { Console.WriteLine("Car is driving"); } public void ApplyBrake() { Console.WriteLine("Car is applying brakes"); } } {CHEEZYCODE}
  • 5. Car beetle = new Car(); 1 When we say new Car(), new object in the memory is created. Memory Locations {CHEEZYCODE}
  • 6. Car beetle = new Car(); 1 When we say new Car(), new object in the memory is created. Object will occupy certain bytes in memory Memory Locations {CHEEZYCODE}
  • 7. Car beetle = new Car(); 1 When we say new Car(), new object in the memory is created. Memory Locations {CHEEZYCODE}
  • 8. Car beetle = new Car(); 1 When we say new Car(), new object in the memory is created. Memory Locations {CHEEZYCODE}
  • 9. Car beetle = new Car(); 1 When we say new Car(), new object in the memory is created. This is new object of Car in memory Memory Locations {CHEEZYCODE}
  • 10. Car beetle = new Car(); 2 This is new object of Car in memory Memory Locations Object has been created, now location of this object is passed as a reference {CHEEZYCODE}
  • 11. Car beetle = new Car(); 3 This is new object of Car in memory Memory Locations Location of this object is stored in beetle to access the car object {CHEEZYCODE}
  • 12. Car beetle = new Car(); 4 beetle Memory Locations Now you can access newly created object in memory with the help of beetle reference {CHEEZYCODE}
  • 13. Car beetle = new Car(); 5 beetle What does this object has? {CHEEZYCODE}
  • 14. Car beetle = new Car(); 5 beetle What does this object has? class Car { //Properties public int modelYear; public string carName; public string carType; public float price; //Methods public void DriveCar() { Console.WriteLine("Car is driving"); } public void ApplyBrake() { Console.WriteLine("Car is applying brakes"); } } Remember this ? {CHEEZYCODE}
  • 15. Car beetle = new Car(); 6 beetle Object stores properties values - it could be another object or built in types like int or float class Car { //Properties public int modelYear; public string carName; public string carType; public float price; //Methods public void DriveCar() { Console.WriteLine("Car is driving"); } public void ApplyBrake() { Console.WriteLine("Car is applying brakes"); } } {CHEEZYCODE}
  • 16. 7beetle beetle object in memory has these properties class Car { //Properties public int modelYear; public string carName; public string carType; public float price; //Methods public void DriveCar() { Console.WriteLine("Car is driving"); } public void ApplyBrake() { Console.WriteLine("Car is applying brakes"); } } modelYear (Integer) carName (String) carType(String) price(float) {CHEEZYCODE}
  • 17. 8 What if I want to create 2 objects? {CHEEZYCODE}
  • 18. 8 What if I want to create 2 objects? Car beetle = new Car(); Car mustang = new Car(); {CHEEZYCODE}
  • 19. 8 What if I want to create 2 objects? Car beetle = new Car(); Car mustang = new Car(); Same process will be followed {CHEEZYCODE}
  • 20. 8 What if I want to create 2 objects? modelYear (Integer) carName (String) carType(String) price(float) modelYear (Integer) carName (String) carType(String) price(float) beetle mustang {CHEEZYCODE}
  • 21. 8 beetle What if I want to create 2 objects? modelYear (Integer) carName (String) carType(String) price(float) modelYear (Integer) carName (String) carType(String) price(float) mustang BOTH OBJECTS ARE DIFFERENT {CHEEZYCODE}
  • 22. 9 Assign values to these properties using dot(.) operator beetle modelYear (Integer) carName (String) carType(String) price(float) Assigning values to these properties. These are similar to variables but they are inside beetle and part of beetle object. {CHEEZYCODE}
  • 23. 9 Assign values to these properties using dot(.) operator beetle modelYear (Integer) carName (String) carType(String) price(float) beetle.modelYear = 2017; beetle.carName = "Volkswagen Beetle“; beetle.carType = "Beetle 1.8T “; beetle.price = 19795F; {CHEEZYCODE}
  • 24. 10 Access these properties using dot operator beetle modelYear (Integer) carName (String) carType(String) price(float) You access the properties of beetle using dot operator {CHEEZYCODE}
  • 25. 10 Assign values to these properties using dot(.) operator beetle modelYear (Integer) carName (String) carType(String) price(float) Console.WriteLine(beetle.modelYear); and similarly you access other properties of object {CHEEZYCODE}
  • 26. Classes And Objects This is how it works behind the scenes {CHEEZYCODE}