Wednesday, 28 March 2018

Classes and Objects

Class :

Class is a user defined data type which is a collection of data members and member function together.

Wrapping of data members and member function together in a single unit is called as class.

Data Members gives the information about object and member function gives the operation on the object or it describes the behavior of the object.

Class helps you for data abstraction as well as for the data encapsulation which gives the advantage of data hiding.

       Syntax of Class Definition:
       class classname
       {
              private:
              //variable declaration;
              public:
              // variable declaration;
              //function declaration;
         };
The keyword 'class' indicates the name of the class. The body of the class enclosed with curly braces followed by semicolon.

The Body of class contain declaration of variables and function collectively called as data members and member function

Class helps you to apply access specifies on data members and member functions.

Data members and member function specified by private access specifies are accessible only to their own class members and not to outsiders but on the other hand public members are accessed to their own members and also from outside class.

Members in the without access specifies are private by default.

Access Specifies public, private are followed by colon.


 
Creating Object :
Declaration of class does not define any objects but specifies what they will contain.Creating object of class called as creating variables of the class. Object of class can be created by using class name like any other variable.

The Syntax is :
 Class_name object_name;
OR
Class_name object_name1,object_name2,object_name3,.........object_name n;

The Memory for the object is created when it is created.

Ex.
       Student xyz;
OR  Student xyz, abc,......;

Objects can also be created when the class is defined by placing their names immediately after the closing brace.

class Student
{
   //Data Members
  // Member Functions
}xyz,abc;

Accessing Class Members :

Once an object of a class has been created , There must provision to access its members. This is achieved by using member access operator that is (.) dot.

The syntax for Accessing Data Members of a class :

Object_name.data_member;

Syntax for accessing Member Function of class :

Object_name.function_name(Actual Arguments);

0 Comments:

Post a Comment

Popular Posts

Categories

AI (33) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (146) C (77) C# (12) C++ (82) Course (67) Coursera (198) Cybersecurity (24) data management (11) Data Science (106) Data Strucures (8) Deep Learning (13) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (21) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (46) Meta (18) MICHIGAN (5) microsoft (4) Nvidia (1) Pandas (3) PHP (20) Projects (29) Python (893) Python Coding Challenge (285) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (42) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses