This document discusses procedural programming versus object-oriented programming. Procedural programming focuses on processes and actions but has limitations when data structures change. Object-oriented programming organizes software around objects that have attributes and behaviors. Classes define objects and act as blueprints, with objects being instantiated from classes at runtime. Classes contain data members and member functions, and can control access using public, private, and protected specifiers. Constructors initialize objects when they are created.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
51 views9 pages
09 Class and Objects
This document discusses procedural programming versus object-oriented programming. Procedural programming focuses on processes and actions but has limitations when data structures change. Object-oriented programming organizes software around objects that have attributes and behaviors. Classes define objects and act as blueprints, with objects being instantiated from classes at runtime. Classes contain data members and member functions, and can control access using public, private, and protected specifiers. Constructors initialize objects when they are created.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9
Class and Objects
Class and Object, Access Modifiers, Constructors
Procedural Programming Procedural programming focuses on the process/actions that occur in a program. The program starts at the beginning, does something, and ends. Limitations of Procedural Programming • If the data structures change, many functions must also be changed • Programs that are based on complex function hierarchies are: • difficult to understand and maintain • difficult to modify and extend • easy to break Object-Oriented Programming • Objected-Oriented Programming is computer programming model that organizes software design around data or Objects(Data fields that have attributes and behaviors) • Object-oriented programming (OOPs) makes development and maintenance easier • OOPs provides data hiding (Abstraction) • OOPs provides the ability to simulate real-world event much more effectively Classes and Objects • Classes • Classes are the standard unit of programming • Model objects that have attributes (data members) and behaviors (member functions) • Defined using keyword class • Have a body delineated with braces ({ and }) • Class definitions terminate with a semicolon • A class is like a blueprint – reusable • For example, a house is an instance of a “blueprint class” Classes and Objects • Objects • Object is a run time entity. • Objects are instantiated (created) from the class • Memory is allocated when object is created
• attributes: members of a class
• methods or behaviors: member
functions of a class Class definition class Class_name { public: constructor and destructor member functions private: data members }; Member access specifiers • Classes can limit the access to their member functions and data • The three types of access a class can grant are: • Public — Accessible wherever the program has access to an object of the class • private — Accessible only to member functions of the class • Protected — Accessible form Child class members only Objects • Class definition and declaration • Once a class has been defined, it can be used as a type in object, array and pointer declarations • Example: Classname objname, //Object of Type Classs ArrayofClass[8], // Array of Type Class *pointofClass, //Pointer to Class Object &referenceofClass; //Reference to Class Object • Accessing class members • Dot (.) for objects and arrow (->) for pointers • Example: • t.hour is the hour element of t • TimePtr->hour is the hour element Initializing Class Objects: Constructors • Constructor : Special Function that • Initialize class members • Same name as the class • No return type • Is executed / called at the time of object creation