Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Object-Oriented Programming: Understanding Classes and Member Access, Slides of Object Oriented Programming

An overview of object-oriented programming (oop) concepts, focusing on classes and member access. It explains how classes are used to define new types, and the benefits of abstraction. The document also covers the syntax for defining a new user-defined type, accessing members, and the use of access specifiers in c++.

Typology: Slides

2011/2012

Uploaded on 08/08/2012

anchita
anchita 🇮🇳

4.4

(7)

115 documents

1 / 22

Toggle sidebar

Related documents


Partial preview of the text

Download Object-Oriented Programming: Understanding Classes and Member Access and more Slides Object Oriented Programming in PDF only on Docsity! Object oriented programming (OOP) Lecture No. 7 docsity.com Class ►Class is a tool to realize objects ►Class is a tool for defining a new type docsity.com Type in C++ ►Mechanism for user defined types are  Structures  Classes ►Built-in types are like int, float and double ►User defined type can be  Student in student management system  Circle in a drawing software docsity.com Abstraction ►Only include details in the system that are required for making a functional system ►Student  Name  Address  Sibling  Father Business Relevant to our problem Not relevant to our problem docsity.com Defining a New User Defined Type class ClassName { … DataType MemberVariable; ReturnType MemberFunction(); … }; Syntax Syntax docsity.com Example Student aStudent; aStudent.rollNo = 514; aStudent.rollNo = -514; //Error docsity.com Object and Class ►Object is an instantiation of a user defined type or a class docsity.com Declaring class variables ►Variables of classes (objects) are declared just like variables of structures and built-in data types TypeName VaraibaleName; int var; Student aStudent; docsity.com Access specifiers docsity.com Access specifiers ►There are three access specifiers  ‘public’ is used to tell that member can be accessed whenever you have access to the object  ‘private’ is used to tell that member can only be accessed from a member function  ‘protected’ to be discussed when we cover inheritance docsity.com Example class Student{ private: char * name; int rollNo; public: void setName(char *); void setRollNo(int); ... }; Cannot be accessed outside class Can be accessed outside class docsity.com Example class Student { char * name; int RollNo; }; class Student { private: char * name; int RollNo; }; docsity.com Example class Student { char * name; int RollNo; void SetName(char *); }; Student aStudent; aStudent.SetName(Ali); Error docsity.com Example class Student { char * name; int RollNo; public: void setName(char *); }; Student aStudent; aStudent.SetName(“Ali”); docsity.com