C++ and Oops
C++ and Oops
Answer:
sizeof . .* .-> :: ?:
Answer:
3. What are the conditions that have to be met for a condition to be an invariant of the class?
Answer:
Example:
template<class T>
class Array2D
public:
class Array1D
public:
...
};
...
};
Array2D<float>data(10,20);
........
cout<<data[3][6]; // fine
Here data[3] yields an Array1D object and the operator [] invocation on that
object yields the float in position(3,6) of the original two dimensional array. Clients
of the Array2D class need not be aware of the presence of the Array1D class.
Objects of this latter class stand for one-dimensional array objects that,
conceptually, do not exist for clients of Array2D. Such clients program as if they
were using real, live, two-dimensional arrays. Each Array1D object stands for a one-
dimensional array that is absent from a conceptual model used by the clients of
Array2D. In the above example, Array1D is a proxy class. Its instances stand for
one-dimensional arrays that, conceptually, do not exist.
➢ Smalltalk,
➢ Java,
➢ Eiffel,
➢ Sather.
Answer:
Message Method
to each other.
void main()
{
int a, *pa, &ra;
pa = &a;
ra = a;
cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra ;
}
Answer :
Compiler Error: 'ra',reference must be initialized
Explanation :
Pointers are different from references. One of the main
differences is that the pointers can be both initialized and assigned,
whereas references can only be initialized. So this code issues an error.
7.What is a modifier?
Answer:
A modifier, also called a modifying function is a member function that
changes the value of at least one data member. In other words, an operation that
modifies the state of an object. Modifiers are also known as ‘mutators’.
8. What is an accessor?
Answer:
An accessor is a class operation that does not modify the state of an object.
The accessor functions need to be declared as const operations
Answer:
Template class:
Class template:
Answer:
Answer: