Professional Documents
Culture Documents
Ans: The objects with the same data structure (attributes) and behavior (operations) are called class.
2. What is an object?
Ans: It is an entity which may correspond to real-world entities such as students, employees, bank
account. It may be concrete such as file system or conceptual such as scheduling policies in
multiprocessor operating system.
Every object will have data structures called attributes and behavior called operations.
Class person
{
private:
char name[20];
int age;
char sex;
public: speak();
walk();
};
7. Define OOPs?
Ans: OOP is a method of implementation in which programs are organized as co-operative collection of
objects, each of which represents an instance of some class and whose classes are all member of a
hierarchy of classes united through the property of inheritance.
17. What is the difference between method overloading and method overriding?
Ans: Overloading a method (or function) in C++ is the ability for functions of the same name to be defined
as long as these methods have different signatures (different set of parameters). Method overriding is the
ability of the inherited class rewriting the virtual method of the base class.
Inheritance: is a feature of OOPL that represents the is a relationship between different objects
(classes). Say in real life a manager is a employee. So in OOPL manger class is inherited from the
employee class.
26. How many ways are there to initialize an int with a constant?
Ans: Two.
There are two formats for initializers in C++ as shown in the example that follows. The first format uses
the traditional C notation. The second format uses constructor notation.
int foo = 123;
int bar (123);
35. What is the difference between a copy constructor and an overloaded assignment operator?
Ans: A copy constructor constructs a new object by using the content of the argument object. An
overloaded assignment operator assigns the contents of an existing object to another existing object of
the same class.
39. What is a container class? What are the types of container classes?
Ans: A container class is a class that is used to hold objects in memory or external storage. A container
class acts as a generic holder. A container class has a predefined behavior and a well-known interface. A
container class is a supporting class whose purpose is to hide the topology used for maintaining the list of
objects in memory. When a container class contains a group of mixed objects, the container is called a
heterogeneous container; when the container is holding a group of objects that are all the same, the
container is called a homogeneous container