A class definition starts with the keyword class followed by the
class name and the class body enclosed by pair of curly braces. It is a group
of related method and variable. Class is a like a blueprint it defines the data
and behaviour of type. You create an instance of this class now referred to as
an object. You can create as many instance of your class as you want to.
Declaring Class
Declaring Class |
- Access specifiers specify the access rules for the members as well as the class itself. By default access specifier for the class type is internal and private for class member.
- To access the class member you will use the object with dot (.) operator.
Create Object
A class defines a type of object. An object is a concrete entity
based on a class and is sometimes referred to as an instance of a class. Object
can be created by using the new keyword. new keyword is used to occupy the
memory space for object.
Every class has a default constructor. A class constructor is a
special member function of a class that is executed whenever we create new
objects of that class.
Member Function and Variable
A member function of a class is a function that has its definition
or its prototype within the class definition like any other variable. The
member of a class is operated by the object. We can also define class members
as static using the static keyword. Such functions can access only static
variables. The static functions exist even before the object is created.
Input |
Output |
----
No comments:
Post a Comment