Custom Search

Saturday, March 2, 2013

OOPS CONCEPT ONE WORD FOR C++


OOPS CONCEPT ONE WORD FOR C++

1. What is friend function? 

As the name suggests, the function acts as a friend to a class. As a friend of a class, it can access its private and protected members. A friend function is not a member of the class. But it must be listed in the class definition.

2. Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array? 

Mergesort always makes recursive calls to sort subarrays that are about half size of the original array, resulting in O(n log n) time.

3. What is abstraction? 

Abstraction is of the process of hiding unwanted details from the user.

4. What are virtual functions? 

A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don't know about the derived class.

5. What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator. 

An internal iterator is implemented with member functions of the class that has items to step through. .An external iterator is implemented as a separate class that can be "attach" to the object that has items to step through. .An external iterator has the advantage that many difference iterators can be active simultaneously on the same object. 

6. What is a scope resolution operator? 

A scope resolution operator (::), can be used to define the member functions of a class outside the class

7. What do you mean by pure virtual functions? 

A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero.
class Shape { public: virtual void draw() = 0; };

8. What is polymorphism? Explain with an example? 

"Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms of object.
Example: function overloading, function overriding, virtual functions. Another example can be a plus ‘+’ sign, used for adding two integers or for using it to concatenate two strings.

9. Why are arrays usually processed with for loop? 

The real power of arrays comes from their facility of using an index variable to traverse the array, accessing each element with the same expression a[i]. All the is needed to make this work is a iterated statement in which the variable i serves as a counter, incrementing from 0 to a.length -1. That is exactly what a loop does.

10. What is an HTML tag? 

Answer: An HTML tag is a syntactical construct in the HTML language that abbreviates specific instructions to be executed when the HTML script is loaded into a Web browser. It is like a method in Java, a function in C++, a procedure in Pascal, or a subroutine in FORTRAN.

11. What are the advantages of inheritance?

• It permits code reusability.
• Reusability saves time in program development.
• It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system becomes functional.

12. What is the difference between declaration and definition?

The declaration tells the compiler that at some later point we plan to present the definition of this declaration.

E.g.: void stars () //function declaration
The definition contains the actual implementation.

E.g.: void stars () // declarator
{
for(int j=10; j>=0; j--) //function body
cout<<”*”;
cout<

13. What is the difference between class and structure? 

Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public. 
Class: Class is a successor of Structure. By default all the members inside the class are private.

14. What is RTTI?

Runtime type identification (RTTI) lets you find the dynamic type of an object when you have only a pointer or a reference to the base type. RTTI is the official way in standard C++ to discover the type of an object and to convert the type of a pointer or reference (that is, dynamic typing). The need came from practical experience with C++. RTTI replaces many Interview Questions - Homegrown versions with a solid, consistent approach.

15. What is encapsulation? 

Packaging an object’s variables within its methods is called encapsulation.

16. What is an object? 

Object is a software bundle of variables and related methods. Objects have state and behavior.

17. How can you tell what shell you are running on UNIX system? 

You can do the Echo $RANDOM. It will return a undefined variable if you are from the C-Shell, just a return prompt if you are from the Bourne shell, and a 5 digit random numbers if you are from the Korn shell. You could also do a ps -l and look for the shell with the highest PID.

18. What do you mean by inheritance? 

Inheritance is the process of creating new classes, called derived classes, from existing classes or base classes. The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of its own.

19. What is virtual class and friend class? 

Friend classes are used when two or more classes are designed to work together and need access to each other's implementation in ways that the rest of the world shouldn't be allowed to have. In other words, they help keep private things private. For instance, it may be desirable for class DatabaseCursor to have more privilege to the internals of class Database than main() has.

20. What is the word you will use when defining a function in base class to allow this function to be a polimorphic function? 

virtual 

21. What do you mean by binding of data and functions? 

Encapsulation.

22. What are 2 ways of exporting a function from a DLL?

1.Taking a reference to the function from the DLL instance.
2. Using the DLL ’s Type Library

23. What is the difference between an object and a class? 

Classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects.
- A Class is static. All of the attributes of a class are fixed before, during, and after the execution of a program. The attributes of a class don't change.
- The class to which an object belongs is also (usually) static. If a particular object belongs to a certain class at the time that it is created then it almost certainly will still belong to that class right up until the time that it is destroyed.
- An Object on the other hand has a limited lifespan. Objects are created and eventually destroyed. Also during that lifetime, the attributes of the object may undergo significant change.

24. Suppose that data is an array of 1000 integers. Write a single function call that will sort the 100 elements data [222] through data [321]. 

quicksort ((data + 222), 100);

25. What is a class? 

Class is a user-defined data type in C++. It can be created to solve a particular kind of problem. After creation the user need not know the specifics of the working of a class.


No comments:

Post a Comment