Object Oriented
Object Oriented
2. Friend Class and Function in C++ : A friend class can access private and
protected members of other classes in which it is declared as a friend.
, and they are not the member of the class .
3.Virtual functions :
A virtual function is a member function declared in a base class and re-declared in
a derived class (overridden). You can execute the virtual function of the derived
class when you refer to its object using a pointer or reference to the base class.
The concept of dynamic binding is implemented with the help of virtual functions.
4. Abstract class
An abstract class is a restricted class that cannot be used to create objects.
5. Objects of any class cannot be made a friend of any other or same class whereas
functions, classes and operator functions can be made a friend.
6. Encapsultion is the concept of binding data and methods and preventing it from
unauthorized access.
Abstraction Example: CAR – the driver of the car only needs to know how to drive
it. Not how its engine and the gear box and other internal components work.
Abstraction is process of hiding the implementation details and showing only the
functionality to the users.
10.An object is an instance of a class i.e. an object represents a class i.e. what
class has(data members) and what it can do(member functions).
11.A class without a name will not have a destructor. The object is made so
constructor is required but the destructor is not.
12.Though C does not allows member functions in structures but C++ allows
structures to have member functions. Members of structures are public by default
and those of classes are private by default. Classes can have protected data
members.
13. Explicit call to a constructor can let you create a temporary instance. This is
because the temporary instances doesn’t have any name. Those are deleted from
memory as soon as their reference is removed.
Implicit calls: The compiler might implicitly call a default constructor (if
available) when you declare an object without arguments. However, these are not
temporary instances as they are assigned to a variable.
Explicit calls: You explicitly use the new keyword followed by the constructor name
and arguments to create a new object. This is the most common way to create
temporary objects.
14. Compiler runs out of memory. This is because while passing the argument by
value, a constructor of the object will be called. That in turn called another
object constructor for values, and this goes on. This is like a constructor call to
itself, and this goes on infinite times, hence it must be passed by reference, so
that the constructor is not called.