Sunday, 1 January, 2012




1.What is a class? Give Example. Or Write the general form for a class
A class is a way to bind the data and its associated functions together.
General Form
class class_name
variable declaration
function declaration
variable declaration
function declaration
variable declaration
function declaration
The keyword class specifies user defined data type class name
The body of a class is enclosed within braces and is terminated
by a semicolon ;
The class body contains the declaration of variables and functions
The class body has three access specifiers ( visibility labels) viz., private , public and protected
2.What are the two parts of a class specification?
A class specification has two parts:
1. Class declaration
2. Class Function Definitions.
3.What are the three access specifiers of class members?(or) List out the accessibility levels in C++.
Private, Public and Protected.
4.What effect does the visibility label private has on the members of a class.
The members that have been declared as private, can be accessed from within the class.
5.What effect does the visibility label protected, has on the members of a class.
The members that have been declared as protected can be accessed from within the class and from the members of the inherited classes.
6.What effect does the visibility label public , has on the members of a class.
The members that have been declared as public can be accessed from outside the class also.
7.What is encapsulation?
The binding of data and functions together into a single entity is referred to as encapsulation.
8.What is mean by data hiding?
  • The members and functions declared under private are not accessible by members outside the class, this is referred to data hiding.
  • Data abstraction is achieved through data hiding.

9.What is data abstraction?
Instruments allowing only selected access of components to objects and to members of other classes is called Data Abstraction.
Data abstraction is achieved through data hiding.
10.What are data members and member functions of a class? Differentiate
Data members are the data variables that represent the features or properties of a class.
  • Data members are also called as attributes.
Member functions are the functions that perform specific tasks in a class.
  • Members functions are called as methods,
11.class student
int Eng, Cs, phy;
int Eco, Comm;
}s1, s2, s3;
Name the objects of class students from the above C++ code.
s1, s2, s3.
13.What is the use of a dot operator?
  • The members of a class are accessed using the dot operator.
stud.execute ( );
Member function - execute ( )
Dot operator - .
Object name - stud
13.Briefly explain how memory is allocated to the objects of a class.
  • The member functions are created and placed in the memory space only when they are defined as a part of the class specification.
  • No separate space is allocated for member functions when the objects are created.
  • Separate space is allocated for member variables when each object is created.
  • Separate memory allocations for the objects are essential because the member variables will hold different data values for different objects.
14.Give some valid points about static data members of a class.
  • It is initialized to zero, only when first object of its class is created. No other initialization is permitted.
  • Only one copy of the member variable is created and is shared by all the other objects of its class type.
  • Its scope or visibility is within the class but its lifetime is the lifetime of the program.
15.What is friend functions?
  • Accessible by only its own members and certain special functions called as friend functions

16.What are the methods to create class objects?
Method I
  • Class variables are known as objects
  • The declaration of an object is similar to that of a variable of any basic type.
Ex. student s;
Student – data type s - object
Method –II
  • Objects can also be created by placing their names immediately after the closing brace of the class declaration.
class student
17.What are the characteristics of member function?
  • Several different classes can use the same function name
  • Member functions can access the private data of a class
  • A member function can call another member function directly, without using the dot operator
  • The member functions can receive arguments of a valid C++ data type.
  • The return type of a member function can be of object data type
  • Member functions can be of static type
18. How to define and declared member functions? or
What are the methods to define a class?
Methods of a class can be defined in both ways.
1.The member function is declared and defined within class .
  • The members defined within the class behave like inline functions.
2.The member function is declared within the class, and defined outside the class.
  • Member functions defined outside the class has the prototype as
Syntax: type class_name :: function name();
19.What does the following statement mean? Or How member function defined outside the class?
void add : : show ( )
  • Member function - show ( ) is a of the class - add
  • It is defined outside the class
  • It does not return any data type.

20.What is Nesting of function?
  • A member function can call another member function directly, without using the dot operator

Book Exercises:

Memory allocation for instance i
Private data Private data
Public data members
Methods or data members that
can be accessed
by i
Code = 2bytes
Quantity =2 bytes
Price = 4 bytes
Tax = 4 bytes
Total = 12 bytes
code , quantity , price
Method: putdata()
Data: tax

No comments:

Post a Comment