C/C++ Programming interview questions and answers
By Satish Shetty, July 14th, 2004
What is encapsulation??
Containing and hiding information about an object, such as internal data structures and code. Encapsulation isolates the plexity of an object's operation from the rest of the application. For example, a ponent asking revenue from a business object need not know the data's origin.
What is inheritance?
Inheritance allows one class to reuse the state and behavior of another class. The derived class inherits the properties and method implementations of the base class and extends it by overriding methods and adding additional properties and methods.
What is Polymorphism??
Polymorphism allows a client to treat different objects in the same way even if they were created from different classes and exhibit different behaviors.
You can use implementation inheritance to achieve polymorphism in languages such as C++ and Java.
Base class object's pointer can invoke methods in derived class objects.
You can also achieve polymorphism in C++ by function overloading and operator overloading.
What is constructor or ctor?
Constructor creates an object and initializes it. It also creates vtable for virtual functions. It is different from other methods in a class.
What is destructor?
Destructor usually deletes any extra resources allocated by the object.
What is default constructor?
Constructor with no arguments or all the arguments has default values.
What is copy constructor?
Constructor which initializes the it's object member variables ( by shallow copying) with another object of the same class. If you don't implement one in your class piler implements one for you.
for example:
Boo Obj1(10); // calling Boo constructor
Boo Obj2(Obj1); // calling boo copy constructor
Boo Obj2 = Obj1;// calling boo copy constructor
When are copy constructors called?
Copy constructors are called in following cases:
a) when a function returns an object of that class by
C++_常见英文面试笔试题 来自淘豆网www.taodocs.com转载请标明出处.