Classes and Objects
Classes and Objects
Define a class
Methods
Methods define the behavior of the objects.
They allow you to perform actions or
calculations related to the object’s state.
Let’s add some methods to the Student class
Property
A property encapsulates a private field using setter and
getter and retrieve underlying field value
You can also apply some
additional logic to get and set.
As seen in the example.
Note:
Get – used to return the
property value
Set – used to assign new
value
Value Keyword – defines
the value being assigned in
the set (Parameter)
Objects
Are instances of a class created with
specifically defined data. Objects can
correspond to real-world objects or an abstract
entity.
An Object A Car
Functions - Start
- Move
- Stop
Objects of a Class
You can create one or more objects of a An object of a class can be crated using the
class. Each object can have different values new keyword and assign that object in a
of properties and fields but methods and variable of a data type.
events behave the same.
You can now access public members of a class using the
object.MemberName notation
You can create multiple objects of a class with different values
of properties and fields.
Thank You for
Listening
Activity: Creating a Class and Object in C#
Instructions: