Q. Overloading Vs Overriding
Function Overloading is the implementation of static polymorphism where same function name having different definitions for different uses.
Function overriding is applicable for dynamic polymorphism where where the function name and the definition are same but the function call is decided at the run time according to the type of object reference.
Q. What is public, protected, private?
Ans:
public, protected, private are access specifiers that is used to implement encapsulation of data at various level.
Private:
* Can be data or method members
* Are private to the class where they are declared
* Accessible ONLY by the member methods of the class where they are declared
* Only exception to the above rule is Friend (explanation of friends is beyond the scope of this topic
* In a C++ class, private is default for member declaration. That is, if you do not specify any access specifier (private, public, protected), the member is considered private
Public:
* Can be data or method members
* Are accessible by any function/method/application globally, so long as an instance of the class where the public members are declared is created.
* These members are accessible only thru an instance of the class where they are declared
* Generally used to define a C++ class behaviour and/or to access private data members (act as private data modifiers)
Protected
* Can be data or method members
* Act exactly as private members for all practical purposes, so long as they are referenced from within the class (and/or instances of the class)where they are declared
* Specifically used to define how certain data/method members of a class would behave in a child class (used to define their behaviour in inheritance)
* The protected members become private of a child class in case of private inheritance, public in case of public inheritance, and stay protected in case of protected inheritance
Q. 2. What is a class?
Ans:
class is a user defined data type,in which data members and member functions are defined.A class can also be defined as a classification/category of objects that have similar
attributes and behaviour.For example, Automobile is a category of objects that have similar attributes, such as wheels, engine, doors, shape, color, cylinders etc., and behaviours,
such as start, run, move, turn etc. Car is an instance of automobile which has different values for the attributes (4 wheels, one engine, 2 or 4 doors, 4/6/8 cylinders, etc),
3.What is an object?
Ans:
In C++, Object is an instance of a Class that has a runtime state, and is associated with certain specific methods that can change its state.
Q. Static Variable
Static variable is stored on the heap, regardless of whether it's declared within a reference type or a value type. There is only one slot in total no matter how many instances are created.
This heap is separate from the normal garbage collected heap - it's known as a "high frequency heap", and there's one per application domain.
Q. What is virtual class and friend class?
Ans:
Virtual Base Class: Used in context of multiple inheritance in C++. If you plan to derive two classes from a class, and further derive one class from the two classes in the second level, you
need to declare the uppermost base class as 'virtual' in the inherited classes. This prevents multiple copies of the uppermost base class data members when an object of the class at the
third level of hierarchy is created.
Friend class: When a class declares another class as its friend, it is giving complete access to all its data and methods including private and protected data and methods to the friend
class member methods.
Friendship is not bi-directional. If A declares B as its friend it does NOT mean that A can access private data of B. It only means that B can access all data of A.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment