InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What Is The Difference Between A Shallow Copy And A Deep Copy? |
|
Answer» A shallow copy SIMPLY creates a new OBJECT and INSERTS in it REFERENCES to the members of the original object. A deep copy CONSTRUCTS a new object and then creates in it copies of each of the members of the original object. A shallow copy simply creates a new object and inserts in it references to the members of the original object. A deep copy constructs a new object and then creates in it copies of each of the members of the original object. |
|
| 2. |
How Is Memory Allocated/deallocated In C ? How About C++ ? |
|
Answer» Memory is ALLOCATED in C using malloc() and freed using FREE(). In C++ the NEW() operator is used to ALLOCATE memory to an OBJECT and the delete() operator is used to free the memory taken up by an object. Memory is allocated in C using malloc() and freed using free(). In C++ the new() operator is used to allocate memory to an object and the delete() operator is used to free the memory taken up by an object. |
|
| 3. |
What Do The Keyword Static And Const Signify? |
|
Answer» When a class member is declared to be of a static type, it MEANS that the member is not an instance variable but a class variable. Such a member is ACCESSED using Classname.Membername (as opposed to Object.Membername). Const is a keyword USED in C++ to specify that an object’s value cannot be changed. When a class member is declared to be of a static type, it means that the member is not an instance variable but a class variable. Such a member is accessed using Classname.Membername (as opposed to Object.Membername). Const is a keyword used in C++ to specify that an object’s value cannot be changed. |
|
| 4. |
What Is Multiple Inheritance ? What Are It’s Advantages And Disadvantages ? |
|
Answer» Multiple Inheritance is the process WHEREBY a sub-class can be DERIVED from more than ONE super class. The advantage of multiple inheritance is that it allows a class to inherit the functionality of more than one base class thus ALLOWING for modeling of complex relationships. The DISADVANTAGE of multiple inheritance is that it can lead to a lot of confusion when two base classes implement a method with the same name. Multiple Inheritance is the process whereby a sub-class can be derived from more than one super class. The advantage of multiple inheritance is that it allows a class to inherit the functionality of more than one base class thus allowing for modeling of complex relationships. The disadvantage of multiple inheritance is that it can lead to a lot of confusion when two base classes implement a method with the same name. |
|
| 5. |
What Is Inheritance ? |
|
Answer» INHERITANCE is the process of deriving classes from other classes. In such a case, the sub-class has an ‘is-a’ relationship with the super class. For e.g. VEHICLE can be a super-class and car can be a sub-class derived from vehicle. In this case a car is a vehicle. The super class ‘is not a’ sub-class as the sub- class is more specialized and may contain additional members as compared to the super class. The greatest advantage of inheritance is that it promotes generic DESIGN and code REUSE. Inheritance is the process of deriving classes from other classes. In such a case, the sub-class has an ‘is-a’ relationship with the super class. For e.g. vehicle can be a super-class and car can be a sub-class derived from vehicle. In this case a car is a vehicle. The super class ‘is not a’ sub-class as the sub- class is more specialized and may contain additional members as compared to the super class. The greatest advantage of inheritance is that it promotes generic design and code reuse. |
|
| 6. |
What Is Data Encapsulation ? |
|
Answer» Data Encapsulation is also known as data hiding. The most IMPORTANT advantage of encapsulation is that it lets the programmer create an object and then provide an interface to the object that other objects can use to call the METHODS PROVIDED by the object. The programmer can change the internal workings of an object but this transparent to other INTERFACING programs as long as the interface REMAINS unchanged. Data Encapsulation is also known as data hiding. The most important advantage of encapsulation is that it lets the programmer create an object and then provide an interface to the object that other objects can use to call the methods provided by the object. The programmer can change the internal workings of an object but this transparent to other interfacing programs as long as the interface remains unchanged. |
|
| 7. |
What Are The Access Privileges In C++ ? What Is The Default Access Level ? |
|
Answer» The access privileges in C++ are private, PUBLIC and PROTECTED. The default access level assigned to MEMBERS of a CLASS is private. Private members of a class are accessible only within the class and by friends of the class. Protected members are accessible by the class itself and it’s sub-classes. Public members of a class can be accessed by anyone. The access privileges in C++ are private, public and protected. The default access level assigned to members of a class is private. Private members of a class are accessible only within the class and by friends of the class. Protected members are accessible by the class itself and it’s sub-classes. Public members of a class can be accessed by anyone. |
|
| 8. |
What Is The Difference Between C And C++ ? Would You Prefer To Use One Over The Other ? |
|
Answer» C is based on STRUCTURED programming whereas C++ supports the object-oriented programming paradigm.Due to the ADVANTAGES inherent in object-oriented programs such as MODULARITY and reuse, C++ is PREFERRED. HOWEVER almost anything that can be built using C++ can also be built using C. C is based on structured programming whereas C++ supports the object-oriented programming paradigm.Due to the advantages inherent in object-oriented programs such as modularity and reuse, C++ is preferred. However almost anything that can be built using C++ can also be built using C. |
|
| 9. |
Explain The Scope Resolution Operator.? |
|
Answer» The scope resolution operator permits a program to REFERENCE an identifier in the global scope that has been hidden by another identifier with the same name in the local scope. The answer can get complicated. It should start with “colon-colon,” however. (Some readers had not heard the term, “scope resolution operator,” but they knew what :: means. You should know the formal names of such things so that you can understand all COMMUNICATION about them.) If you claim to be well into the design or use of classes that employ INHERITANCE, you tend to address overriding virtual function OVERRIDES to explicitly call a function higher in the hierarchy. That’s good knowledge to demonstrate, but address your comments specifically to global scope resolution. Describe C++’s ABILITY to override the particular C behavior where identifiers in the global scope are always hidden by similar identifiers in a local scope. The scope resolution operator permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope. The answer can get complicated. It should start with “colon-colon,” however. (Some readers had not heard the term, “scope resolution operator,” but they knew what :: means. You should know the formal names of such things so that you can understand all communication about them.) If you claim to be well into the design or use of classes that employ inheritance, you tend to address overriding virtual function overrides to explicitly call a function higher in the hierarchy. That’s good knowledge to demonstrate, but address your comments specifically to global scope resolution. Describe C++’s ability to override the particular C behavior where identifiers in the global scope are always hidden by similar identifiers in a local scope. |
|
| 10. |
What Is Cin And Cout? |
|
Answer» They are objects corresponding to a program’s default input and output files. Contrast procedural and object oriented programming. The procedural paradigm performs computation through a step-by-step manipulation of data items. Solving PROBLEMS this WAY is akin to writing a recipe. ie: All the ingredients (data items) are defined. Next a series of enumerated steps (statements) are defined to transform the raw ingredients into a finished meal. The object oriented model, in contrast, combines related data and procedural information into a SINGLE package called an object. Objects are meant to represent logically separate entities (like real world objects). Objects are grouped TOGETHER (and defined by) classes. (This is analogous to user defined data types in procedural languages.) Classes may pass-on their “makeup” to classes derived from them. In this way, Objects that are of a similar yet different nature need not be defined from scratch. Computation occurs though the intercommunication of objects. Programming this way is like writing a play. First the CHARACTERS are defined with their attributes and personalities. Next the dialog is written so that the personalities interact. The sum total constitutes a drama. They are objects corresponding to a program’s default input and output files. Contrast procedural and object oriented programming. The procedural paradigm performs computation through a step-by-step manipulation of data items. Solving problems this way is akin to writing a recipe. ie: All the ingredients (data items) are defined. Next a series of enumerated steps (statements) are defined to transform the raw ingredients into a finished meal. The object oriented model, in contrast, combines related data and procedural information into a single package called an object. Objects are meant to represent logically separate entities (like real world objects). Objects are grouped together (and defined by) classes. (This is analogous to user defined data types in procedural languages.) Classes may pass-on their “makeup” to classes derived from them. In this way, Objects that are of a similar yet different nature need not be defined from scratch. Computation occurs though the intercommunication of objects. Programming this way is like writing a play. First the characters are defined with their attributes and personalities. Next the dialog is written so that the personalities interact. The sum total constitutes a drama. |
|
| 11. |
What Is Operator Overloading? |
|
Answer» It is the process of, and ability to redefine the way an OBJECT responds to a C++ OPERATOR symbol. This would be done in the object’s class definition. It is the process of, and ability to redefine the way an object responds to a C++ operator symbol. This would be done in the object’s class definition. |
|
| 12. |
Compare And Contrast C And C++.? |
|
Answer» Comparison: C++ is an extension to the C language. When C++ is used as a procedural language, there are only MINOR SYNTACTICAL differences between them. Contrast: When used as a procedural language, C++ is a better C because:
As an object oriented language, C++ introduces much of the OOP paradigm while allowing a mixture of OOP and procedural styles. Comparison: C++ is an extension to the C language. When C++ is used as a procedural language, there are only minor syntactical differences between them. Contrast: When used as a procedural language, C++ is a better C because: As an object oriented language, C++ introduces much of the OOP paradigm while allowing a mixture of OOP and procedural styles. |
|
| 13. |
In C++ What Is A Constructor? A Destructor? |
|
Answer» A constructors and DESTRUCTORS are methods defined in a class that are invoked AUTOMATICALLY when an object is CREATED or destroyed. They are used to initialize a newly allocated object and to cleanup behind an object about to be REMOVED. A constructors and destructors are methods defined in a class that are invoked automatically when an object is created or destroyed. They are used to initialize a newly allocated object and to cleanup behind an object about to be removed. |
|
| 14. |
What Is A Method? |
|
Answer» A METHOD is a class’s procedural RESPONSE to a given MESSAGE protocol. It is like the definition of a PROCEDURE in other languages. A method is a class’s procedural response to a given message protocol. It is like the definition of a procedure in other languages. |
|
| 15. |
What Are Class Variables? |
|
Answer» These REPRESENT a CLASS’s MEMORY which it SHARES with each of its INSTANCES. These represent a class’s memory which it shares with each of its instances. |
|
| 16. |
What Are Instance Variables? |
|
Answer» These REPRESENT an object’s private memory. They are defined in an object’s CLASS. These represent an object’s private memory. They are defined in an object’s class. |
|
| 17. |
What Is Polymorphism? |
|
Answer» Polymorphism refers to the ability of an OBJECT to respond in a logically identical fashion to MESSAGES of the same protocol, containing differing types of objects. Consider 1 + 5 and 1 + 5.1. In the former, the MESSAGE “+ 5” is sent to an object of class integer (1). In the later, the message “+ 5.1” is sent to the same integer object. The form of the message (its protocol) is identical in both cases. What differs is the type of object on the right-hand side of these messages. The former is an integer object (5) while the later is a floating point object (5.1). The receiver (1) appears (to other objects) to respond in the same way to both messages. Internally, however, it knows that it MUST treat the two types of objects differently in ORDER to obtain the same overall response. Polymorphism refers to the ability of an object to respond in a logically identical fashion to messages of the same protocol, containing differing types of objects. Consider 1 + 5 and 1 + 5.1. In the former, the message “+ 5” is sent to an object of class integer (1). In the later, the message “+ 5.1” is sent to the same integer object. The form of the message (its protocol) is identical in both cases. What differs is the type of object on the right-hand side of these messages. The former is an integer object (5) while the later is a floating point object (5.1). The receiver (1) appears (to other objects) to respond in the same way to both messages. Internally, however, it knows that it must treat the two types of objects differently in order to obtain the same overall response. |
|
| 18. |
To What Does Message Protocol Refer? |
|
Answer» An object’s MESSAGE PROTOCOL is the exact FORM of the set of messages to which the object can RESPOND. An object’s message protocol is the exact form of the set of messages to which the object can respond. |
|
| 19. |
What Is Inheritance? |
|
Answer» Inheritance is property such that a parent (or super) CLASS passes the CHARACTERISTICS of itself to children (or sub) classes that are derived from it. The sub-class has the option of modifying these characteristics in order to make a different but fundamentally RELATED class from the super-class. Inheritance is property such that a parent (or super) class passes the characteristics of itself to children (or sub) classes that are derived from it. The sub-class has the option of modifying these characteristics in order to make a different but fundamentally related class from the super-class. |
|
| 20. |
What Is A Super-class? |
|
Answer» GIVEN a CLASS, a super-class is the basis of the class under consideration. The given class is defined as a subset (in some respects) of the super-class. OBJECTS of the given class potentially posses all the characteristics BELONGING to objects of the super-class. Given a class, a super-class is the basis of the class under consideration. The given class is defined as a subset (in some respects) of the super-class. Objects of the given class potentially posses all the characteristics belonging to objects of the super-class. |
|
| 21. |
What Is An Instance? |
|
Answer» An INDIVIDUAL OBJECT that is a MEMBER of some CLASS. An individual object that is a member of some class. |
|
| 22. |
What Is A Message? |
|
Answer» A message is a signal from ONE object to ANOTHER requesting that a computation TAKE place. It is roughly equivalent to a function CALL in other LANGUAGES. A message is a signal from one object to another requesting that a computation take place. It is roughly equivalent to a function call in other languages. |
|
| 23. |
What Is An Object In C++? |
|
Answer» An OBJECT is a package that contains RELATED DATA and instructions. The data relates to what the object REPRESENTS, while the instructions DEFINE how this object relates to other objects and itself. An object is a package that contains related data and instructions. The data relates to what the object represents, while the instructions define how this object relates to other objects and itself. |
|