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

100 Python Programs for Beginner (53) AI (34) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (173) C (77) C# (12) C++ (82) Course (67) Coursera (226) Cybersecurity (24) data management (11) Data Science (128) Data Strucures (8) Deep Learning (20) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (34) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (59) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (3) Pandas (4) PHP (20) Projects (29) Python (932) Python Coding Challenge (358) Python Quiz (23) Python Tips (2) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (3) Software (17) SQL (42) UX Research (1) web application (8) Web development (2) web scraping (2)

Followers

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