Unit 2-Model Paper QA
Unit 2-Model Paper QA
Unit 2
Q: Define class and object.
Ans:
Class:
Class is a user defined data type that combines data and functions together. It is a collection of objects of
similar type.
Object:
It is a basic run time entity that represents a person, place or any item that the program has to handle.
Description:-
1. Include header files
In this section a programmer include all header files which are require to execute given program. The
most important file is iostream.h header file. This file defines most of the C++statements like cout and
cin. Without this file one cannot load C++ program.
2. Class Declaration
In this section a programmer declares all classes which are necessary for given program. The programmer
uses general syntax of creating class.
3. Member Functions Definition
This section allows programmer to design member functions of a class. The programmer can have inside
declaration of a function or outside declaration of a function.
4. Main Function Program
In this section programmer creates objects and calls various functions writer within various class.
A class can have more than one constructor A class can have at the most one destructor
Constructor accepts parameters. Also it can have Destructor never accepts any parameter.
default value for its parameter.
Syntax: Syntax:
classname() destructor name is preceded with tilde.
{… ~classname()
… {….
} ….
}
Example: Example:
ABC() ~ABC()
{ {
… ….
} }