C++ have various type of datatype like integer ,double ,char
that are not sufficient some time to solving real-time problem. Real-life
problem is not just adding two integer together or string it’s really very
complex. Just think about you are going to ATM to withdrawal some cash. This is
practical example where programming really make changes.
While studying programming object is most often use keyword
.What is really object is. Your computer is an object or your mobile is also a
kind of object. In Programing terms we can say “An object is combination of
data and operation performed in same object”. Ex- Your mobile phone has ram,
camera and other things, and you have function in your phone to operate these things.
In any programing concept when, data or we can say attribute are combine with
operation (methods) is known as class. The class is also called a new user
defined type datatype. Struct concept of C is same as class.
The syntax for class
class name_of_class //class declaration {
Class attribute and members
};// Do not forget the semicolon here
Error identification “If you miss semicolon while defining
class this tends to show error”
Member Function
In class member function is called methods. Its same as
normal function just define inside class. Definition of class can be inside or
outside its really does not matter.
Class syntax with member function
class name_of_class
int attribute1;
{Private:
public:
void method_1(){ //code inside method_1}
};
Member function of class will be private or public depends
on the nature of method. The member need to be accessed outside are declared public,
and that is not freely accessed are defined private.
Note
If method definition are outside to class boundary then use :: (scope-operator).If definition is inside we do not need this operator.
0 Comments
If you have any doubt and suggestion Please let me know