41. What is a virtual destructor?
Ans: The simple answer is that a virtual destructor is one that is declared with the virtual attribute.
42. What is an incomplete type?
Ans: Incomplete type refers to pointers in which there is non availability of the implementation of the referenced location or it points to some location whose value is not available for modification.
Example:
int *i=0×400 // i points to address 400
*i=0; //set the value of memory location pointed by i.
Incomplete types are otherwise called uninitialized pointers.
43. What is class invariant?
Ans: A class invariant is a condition that defines all valid states for an object. It is a logical condition to ensure the correct working of a class. Class invariants must hold when an object is created, and they must be preserved under all operations of the class. In particular all class invariants are both preconditions and post-conditions for all operations or member functions of the class.
Advertisement
Ans: The simple answer is that a virtual destructor is one that is declared with the virtual attribute.
42. What is an incomplete type?
Ans: Incomplete type refers to pointers in which there is non availability of the implementation of the referenced location or it points to some location whose value is not available for modification.
Example:
int *i=0×400 // i points to address 400
*i=0; //set the value of memory location pointed by i.
Incomplete types are otherwise called uninitialized pointers.
43. What is class invariant?
Ans: A class invariant is a condition that defines all valid states for an object. It is a logical condition to ensure the correct working of a class. Class invariants must hold when an object is created, and they must be preserved under all operations of the class. In particular all class invariants are both preconditions and post-conditions for all operations or member functions of the class.
Advertisement
44. Name some pure object oriented languages?
Ans: Smalltalk, Java, Eiffel, Sather.
45. Name the operators that cannot be overloaded?
Ans: sizeof, ., .*, .->, ::, ?:
46. How can we access protected and private members of a class?
Ans: In the case of members protected and private, these could not be accessed from outside the same class at which they are declared. This rule can be transgressed with the use of the friend keyword in a class, so we can allow an external function to gain access to the protected and private members of a class.
Advertisement
Ans: Smalltalk, Java, Eiffel, Sather.
45. Name the operators that cannot be overloaded?
Ans: sizeof, ., .*, .->, ::, ?:
46. How can we access protected and private members of a class?
Ans: In the case of members protected and private, these could not be accessed from outside the same class at which they are declared. This rule can be transgressed with the use of the friend keyword in a class, so we can allow an external function to gain access to the protected and private members of a class.
Advertisement
47. What is a Null object?
Ans: It is an object of some class whose purpose is to indicate that a real object of that class does not exist. One common use for a null object is a return value from a member function that is supposed to return an object with some specified properties but cannot find such an object.
48. What is a dangling pointer?
Ans: A dangling pointer arises when you use the address of an object after its lifetime is over. This may occur in situations like returning addresses of the automatic variables from a function or using the address of the memory block after it is freed. Example: The following code snippet shows this:
class Sample
{
public:
int *ptr;
Sample(int i)
{
ptr = new int(i);
}
~Sample()
{
delete ptr;
}
void PrintVal()
{
cout << “The value is ” << *ptr;
}
};
void SomeFunc(Sample x)
{
cout << “Say i am in someFunc ” << endl;
}
int main()
{
Sample s1= 10;
SomeFunc(s1);
s1.PrintVal();
}
In the above example when PrintVal() function is called it is called by the pointer that has been freed by the destructor in SomeFunc.
49. What do you mean by late binding?
Ans: Late binding refers to function calls that are not resolved until run time. Virtual functions are used to achieve late binding. When access is via a base pointer or reference, the virtual function actually called is determined by the type of object pointed to by the pointer.
50. Differentiate between the message and method?
Ans:
Message:
Objects communicate by sending messages to each other.
A message is sent to invoke a method.
Method
Provides response to a message and it is an implementation of an operation
51. What is virtual function?
Ans: A virtual function is a member function that is declared within a base class and
redefined by a derived class .To create a virtual function, the function declaration in the base class is preceded by the keyword virtual.
Ans: It is an object of some class whose purpose is to indicate that a real object of that class does not exist. One common use for a null object is a return value from a member function that is supposed to return an object with some specified properties but cannot find such an object.
48. What is a dangling pointer?
Ans: A dangling pointer arises when you use the address of an object after its lifetime is over. This may occur in situations like returning addresses of the automatic variables from a function or using the address of the memory block after it is freed. Example: The following code snippet shows this:
class Sample
{
public:
int *ptr;
Sample(int i)
{
ptr = new int(i);
}
~Sample()
{
delete ptr;
}
void PrintVal()
{
cout << “The value is ” << *ptr;
}
};
void SomeFunc(Sample x)
{
cout << “Say i am in someFunc ” << endl;
}
int main()
{
Sample s1= 10;
SomeFunc(s1);
s1.PrintVal();
}
In the above example when PrintVal() function is called it is called by the pointer that has been freed by the destructor in SomeFunc.
49. What do you mean by late binding?
Ans: Late binding refers to function calls that are not resolved until run time. Virtual functions are used to achieve late binding. When access is via a base pointer or reference, the virtual function actually called is determined by the type of object pointed to by the pointer.
50. Differentiate between the message and method?
Ans:
Message:
Objects communicate by sending messages to each other.
A message is sent to invoke a method.
Method
Provides response to a message and it is an implementation of an operation
51. What is virtual function?
Ans: A virtual function is a member function that is declared within a base class and
redefined by a derived class .To create a virtual function, the function declaration in the base class is preceded by the keyword virtual.