📖 Samacheer Kalvi · 11th TN - English Medium · Computer Science · Page 239question

Unit IV · Part 3

Chapter 3: 4 · Computer Science

function to set the width. b.printWidth( ); //Use member function to print the width. return ; Output: The width of the box is... Illustration .

Inline and Outline member function Absence of access specifier means that members are private by default.. Chapter Page - - Note Declaring a member function having looping construct, switch or goto statement as inline is not advisable. . Creating Objects A class specification just defines the properties of a class.

To make use of a class, the variables of that class type have to be declared. The class variables are called object . Objects are also called as instance of class. For example student s; In the above statement s is an instance of the class student .

Objects can be created in two methods, ( ) Global object ( ) Local object ( ) Global Object If an object is declared outside all the function bodies or by placing their names immediately after the closing brace of the class declaration then it is called as Global object . These objects can be used by any function in the program ( ) Local Object If an object is declared with in a function then it is called local object . It cannot be accessed from outside the function. # include <iostream> # include <conio> using namespace std class add int a,b; public: int sum; void getdata() a= ; b= ; sum = a+b; } a1; //global object add a2; //global object int main() add a3; // Local object a1.getdata(); a2.getdata(); a3.getdata(); cout<<a1.sum; cout<<a2.sum; cout<<a3.sum; return ; Output: 151515 Illustration .

The use of local and global object ACTIVITY Identify the error in the following code fragment class A float x; void init() A a1; X1. = ; }}; void main() { A1.init(); } Chapter Page - - . Memory allocation of objects The member functions are created and placed in the memory space only when they are defined as a part of the class specification. Since all the objects belonging to that class use the same member function, no separate space is allocated

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →