Anda di halaman 1dari 23

OOPS

Concepts
1. Inventor
of C++ language is
A. John Dell
B. Bjarne Stroustrup
C. Thomusn Steve
D. Karl Thomus
Answer : B
2.Which of the following is not a type of constructor?
A. Copy constructor
B. Friend constructor
C. Default constructor
D. Parameterized constructor
Answer: B
Friend is a function to access private members of 2 different classes
to which it has been declared as friend.

3. What is difference between C and C++ ?


C++ is Multi-Paradigm ( not pure OOP, supports both procedural
and object oriented) while C follows procedural style programming.
In C data security is less, but in C++ you can use modifiers for your
class members to make it inaccessible from outside.
C follows top-down approach ( solution is created in step by step
manner, like each step is processed into details as we proceed ) but C+
+ follows a bottom-up approach ( where base elements are established
first and are linked to make complex solutions ).
C++ supports function overloading while C does not support it.
C++ allows use of functions in structures, but C does not permit that.
C++ supports reference variables ( two variables can point to same
memory location ). C does not support this.
C does not have a built in exception handling framework, though we
can emulate it with other mechanism. C++ directly supports
exception handling, which makes life of developer easy.

4.Which of the following is not the member of class?


A. Static function
B. Friend function
C. Const function
D. Virtual function
Answer: B
5.Which of the following concepts means determining at runtime
what method to invoke?
A. Data hiding
B. Dynamic Typing
C. Dynamic binding
D. Dynamic loading
Answer: C

4.Which of the following cannot be legitimately passed to a


function
A.A constant B. A variable. C. A structure D.A header file.
Answer :D
5. this pointer
A. implicitly points to an object
B. can be explicitly used in a class.
C. can be used to return an object.
D. All of the above.
Answer : D.

6. Following are the object oriented programming


language
A. JAVA
B. C++
C. Small talk
D. All of above
Answer : All of above
7. How many words can be read by cin?
A. one B. Two
C. Three
D. Four
Answer : one
Time

// Using >> on a stream reads one word at a

8. RunTime Polymorphism is achieved by ______


A. friend function
B. virtual function
C. operator overloading
D. function overloading
Answer : B

9. Class members are by default


A. Public
B. Private
C. Protected

D. Inherited

Answer : B
10. The null character will take space of
A. 0 byte
B. 2 byte
C.1 byte D. 8 byte
Answer :C

11. Explain storage qualifiers in C++.


i) Const - that memory once initialized, should not be altered by a
program..
ii) Volatile - is a type qualifier used to declare an object or variable value

that can be modified by other than the statement in the source codes
itself, such as interrupt service routine and memory-mapped I/O port or
concurrent thread execution.
iii) Mutable - particular member of a structure or class can be altered
even if a particular structure variable, class, or class member
function is constant..

struct data
{
char name[80];
mutable double salary;
}
const data MyStruct = { "Satish ", 1000 }; //initlized by complier
strcpy ( MyStruct.name, "Shilpa "); // compiler error
MyStruct.salaray = 2000 ; // complier is happy allowed
12. What happens when a class with parameterized constructors and
having no default constructor is used in a program and we create an
object that needs a zero-argument constructor?
A. Compile-time error.
B. Preprocessing error.
C. Runtime error.
D. Runtime exception.
Answer: Option A

13. Can a class have virtual destructor?


A. Yes
B. No
Answer: A
Destructor can be virtual because whenever the object goes in out of the
scope then we have to delete it explicitly i.e. we need to call the
destructor explicitly so destructor should made as virtual destructor like
same as virtual function.
14. For automatic objects, constructors and destructors are called
each time the objects
A. enter and leave scope
B. inherit parent class
C. are constructed
D. are destroyed
Answer: A

15. Copy constructor must receive its arguments by


__________ .
A. either pass-by-value or pass-by-reference
B. only pass-by-value
C. only pass-by-reference
D. only pass by address
Answer: C
16. Constructors __________ to allow different approaches
of object construction.
A. cannot overloaded
B. can be overloaded
C. can be called
D. can be nested
Answer: B

17. Which of the following cannot be declared as virtual?


A.Constructor
B. Destructor
C. Data Members
D. Both A and C
Answer: D
18. Write a C program that wont compile in C++
In C, a void pointer can directly be assigned to some other
pointer like int *, char *. But in C++, a void pointer must be
explicitly typcasted.
#include <stdio.h>
int main()
{
void *vptr;
int *iptr = vptr; //In C++, it must be replaced with int *iptr=(int
*)vptr;
return 0;
}

19. What is the difference between class and structure?


Answer: In class the data members by default are private but in
structure they are by default public.
Structures doesn't provide something like data hiding which is provided
by the classes.
20. How variable declaration in c++ differs that in c?
Answer: C requires all the variables to be declared at the beginning of a
scope but in c++ we can declare variables anywhere in the scope. This
makes the programmer easier to understand because the variables are
declared in the context of their use.
21. What do you mean by inline function?
Answer: An inline function is a function that is expanded inline when
invoked.ie. the compiler replaces the function call with the
corresponding function code.

22.What is a template?
Answer: Templates allow us to create generic functions that admit any
data type as parameters and return a value without having to overload the
function with all the possible data types
23. What is an incomplete type?
Ans: Incomplete type refers to pointers in which there is non availability
of the implementation of the referenced location or it points to some
location whose value is not available for modification.
Example:
int *i=0400 // i points to address 400
*i=0; //set the value of memory location pointed by i.
Incomplete types are otherwise called uninitialized pointers.

24. Name the operators that cannot be overloaded?


., ->(Member Access or Dot operator) , ?: (Ternary or Conditional
Operator ), :: (Scope Resolution Operator), sizeof (Object size Operator)
25. What is the difference between compile time and run time
polymorphism?
Function overloading, operator overloading,and parametric types
(templates in C++ or generics in Java) are done at compile time.
Dynamic binding (virtual functions) is runtime polymorphism.
26. What are concrete classes?
Concrete classes can be instantiated (in other words, objects can be
created from concrete classes). These classes have no abstract methods.

27.What are monomorphic and polymorphic classes?


Classes that do not have any virtual functions (runtime polymorphism)
are known as monomorphic classes.
The classes that have virtual functions (or virtual base classes) and are
designed for making use of runtime polymorphism are known
as polymorphic classes.
28. 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. Any class containing any pure virtual
function cannot be used to create object of its own type.
29. What is STL? what are the components of stl?
A collection of generic classes and functions is called as Standard
Template Library (STL).The stl components are
1. Containers 2. Algorithm 3. Iterators

30. Which class allow primitive types to be accessed as objects


A. Storage
B. Virtual
C.Friend
D.Wrapper
Answer : B
31. What happens when a pointer deleted twice?
A. It can abort the program
B.It can cause a failure
B. It can cause an error
D.It can cause a trap
Answer :D
32.inline functions are invoked at the time of
A. Run time
B. Compile time
C. Depends on how it is invoked
D. Both b and c above
Answer : B
33. Does a class inherit the constructors of its super class?
A class does not inherit constructors from any of its super classes.
34. What is size of a empty class?
One bytev

34. Which of the following two statements call copy constructor and
which one calls assignment operator?
MyClass t1, t2;
MyClass t3 = t1; // ----> (1) //copy constructor
t2 = t1;
// -----> (2) //Copy constructor is called when a new object
is created from an existing object. Assignment operator is called when
an already initialized object is assigned a new value from another
existing object. 2) calls assignment operator..
35. Which pointer is implicit pointer passed as the first argument for
non-static member functions?
A. self pointer
B.std::auto_ptr pointer
C. Myself pointer
D.this pointer
Answer : D
36. How should runtime errors be handled in C++?
The runtime errors in C++ can be handled using exceptions.

37. What is the use of default constructor?


It is a constructor that does not accept any parameters.
If there is no user-defined constructor for a class, the compiler
declares a default parameter less constructor called default
constructor.
38. Do you think the following code is fine? If not, what is the
problem?
T *p = 0;
delete p;
No, the code has a problem. The program will crash in an attempt to
delete a null pointer.
39.How are objects in cpp passed ?
a) By value
b) By reference
Answer: b

40. Consider the following program:


# include
class x
{
public:
int a;
x();
};
x::x()
{
a=10;
cout<<a;
}

class b:public x
{public: b();
};
b::b()
{ a=20; cout<<a;}
main ()
{ b temp; }
What will be the output of this program?
a) 10
b) 20
c) 20 10
Answer: b

d) 10 20

40 . Static member of a class is


a) class specific
b) Object specific
c) Referenced by using the scope resolution operator
d) a & c
Answer : a

41. Say true or false


If any base class contains a constructor with one or more argument ,
then it is mandatory for the derived class to have a constructor and
pass the arguments to the base class constructors
A. True
B. false
Answer : A
//As long as the base class doesnt have a constructor With one or more
arguments , the derived class need not have a constructor function
42. In what all the scenarios I can use copy constructors?
A.When initializing a new object with an existing object
b. When passing an object to a function by value
c. When returning an object from a function by value
d. All three are correct
Answer : D

43. What is an abstract class?


Answer: A class with at least one pure virtual function in it
44. Which of the following statements are false regarding virtual
functions
A. A virtual function can be a friend of another class
B. They cannot be static members
C. We cannot have virtual constructors
D. Virtual functions need not be member of any class
Answer : D // a virtual function must be member of a class

45. What is the output of below C++ program,


class base
{
public :
virtual void disp()=0;
};
int main()
{
cout <<hello world;
base b;
}
A. Hello world
B. Complie time error in base b; you cant create object for an abstract class
C. Compile time error in virtual void disp()=0;
D. none
Answer : B

http://skillgun.com/cpp/constructors/i
nterview-questions-andanswers/paper/237

Anda mungkin juga menyukai