Oopss
Oopss
a) Andrea Ferro
b) Adele Goldberg
c) Alan Kay
d) Dennis Ritchie
View Answer
Answer: c
Explanation: Alan Kay invented OOP, Andrea Ferro was a part of SmallTalk Development. Dennis
invented C++ and Adele Goldberg was in team to develop SmallTalk but Alan actually had got
rewarded for OOP.
Answer: d
Explanation: Duplicate/Redundant data is dependent on programmer and hence can’t be
guaranteed by OOP. Code reusability is done using inheritance. Modularity is supported by using
different code files and classes. Codes are more efficient because of features of OOP.
3. Which was the first purely object oriented programming language developed?
a) Kotlin
b) SmallTalk
c) Java
d) C++
View Answer
Answer: b
Explanation: SmallTalk was the first programming language developed which was purely object
oriented. It was developed by Alan Kay. OOP concept came into the picture in 1970’s.
Answer: c
Explanation: OOP first came into picture in 1970’s by Alan and his team. Later it was used by some
programming languages and got implemented successfully, SmallTalk was first language to use
pure OOP and followed all rules strictly.
5. Which feature of OOP indicates code reusability?
a) Abstraction
b) Polymorphism
c) Encapsulation
d) Inheritance
View Answer
Answer: d
Explanation: Inheritance indicates the code reusability. Encapsulation and abstraction are meant
to hide/group data into one element. Polymorphism is to indicate different tasks performed by a
single entity.
advertisement
Answer: a
Explanation: We need not include any specific header file to use OOP concept in C++, only specific
functions used in code need their respective header files to be included or classes should be
defined if needed.
Answer: b
Explanation: As Java supports usual declaration of data variables, it is partial implementation of
OOP. Because according to rules of OOP, object constructors must be used, even for declaration of
variables.
Answer: c
Explanation: Platform independence is not feature of OOP. C++ supports OOP but it’s not a
platform independent language. Platform independence depends on the programming language.
9. Which is the correct syntax of inheritance?
a) class base_classname :access derived_classname{ /*define class body*/ };
b) class derived_classname : access base_classname{ /*define class body*/ };
c) class derived_classname : base_classname{ /*define class body*/ };
d) class base_classname : derived_classname{ /*define class body*/ };
View Answer
Answer: b
Explanation: Firstly, keyword class should come, followed by the derived class name. Colon is must
followed by access in which base class has to be derived, followed by the base class name. And
finally the body of class. Semicolon after the body is also must.
Answer: a
Explanation: Encapsulation is indicated by use of classes. Inheritance is shown by inheriting the
student class into topper class. Polymorphism is not shown here because we have defined the
constructor in the topper class but that doesn’t mean that default constructor is overloaded.
11. The feature by which one object can interact with another object is _____________
a) Message reading
b) Message Passing
c) Data transfer
d) Data Binding
View Answer
Answer: b
Explanation: The interaction between two object is called the message passing feature. Data
transfer is not a feature of OOP. Also, message reading is not a feature of OOP.
12. Which among the following, for a pure OOP language, is true?
a) The language should follow at least 1 feature of OOP
b) The language must follow only 3 features of OOP
c) The language must follow all the rules of OOP
d) The language should follow 3 or more features of OOP
View Answer
Answer: c
Explanation: The language must follow all the rules of OOP to be called a purely OOP language.
Even if a single OOP feature is not followed, then it’s known to be a partially OOP language.
13. How many types of access specifiers are provided in OOP (C++)?
a) 4
b) 3
c) 2
d) 1
View Answer
Answer: b
Explanation: Only 3 types of access specifiers are available. Namely, private, protected and public.
All these three can be used according to the need of security of members.
14. In multilevel inheritance, which is the most significant feature of OOP used?
a) Code efficiency
b) Code readability
c) Flexibility
d) Code reusability
View Answer
Answer: d
Explanation: The classes using multilevel inheritance will use the code in all the subsequent
subclasses if available. Hence the most significant feature among the options given is code
reusability. This feature is generally intended to use the data values and reuse the redundant
functions.
Answer: a
Explanation: It is a way of combining both data members and member functions, which operate on
those data members, into a single unit. We call it a class in OOP generally. This feature have helped
us modify the structures used in C language to be upgraded into class in C++ and other languages.
Answer: b
Explanation: It never increases function definition overhead, one way or another if you don’t use
polymorphism, you will use the definition in some other way, so it actually helps to write efficient
codes.
17. Which constructor will be called from the object created in the below C++ code?
class A
int i;
A()
i=0; cout<<i;
A(int x=0)
i=x; cout<<I;
};
A obj1;
a) Parameterized constructor
b) Default constructor
c) Run time error
d) Compile time error
View Answer
Answer: d
Explanation: When a default constructor is defined and another constructor with 1 default value
argument is defined, creating object without parameter will create ambiguity for the compiler. The
compiler won’t be able to decide which constructor should be called, hence compile time error.
Answer: a
Explanation: It includes hiding the implementation part and showing only the required data and
features to the user. It is done to hide the implementation complexity and details from the user. And
to provide a good interface in programming.
Answer: b
Explanation: Only insertion operator can be overloaded among all the given options. And the
polymorphism can be illustrated here only if any of these is applicable of being overloaded.
Overloading is type of polymorphism.
20. In which access should a constructor be defined, so that object of the class can be created in
any function?
a) Any access specifier will work
b) Private
c) Public
d) Protected
View Answer
Answer: c
Explanation: Constructor function should be available to all the parts of program where the object
is to be created. Hence it is advised to define it in public access, so that any other function is able
to create objects.
21. Which among the following is correct for the class defined below?
class student
int marks;
public: student(){}
student(int x)
marks=x;
}
};
main()
student s1(100);
student s2();
student s3=100;
return 0;
Answer: d
Explanation: It is a special case of constructor with only 1 argument. While calling a constructor
with one argument, you are actually implicitly creating a conversion from the argument type to the
type of class. Hence you can directly specify the value of that one argument with assignment
operator.
Answer: c
Explanation: When an object is passed to a function, actually its copy is made in the function. To
copy the values, copy constructor is used. Hence the object being passed and object being used in
function are different.
23. Which constructor will be called from the object obj2 in the following C++ program?
class A
int i;
A()
{
i=0;
A(int x)
i=x+1;
A(int y, int x)
i=x+y;
};
A obj1(10);
A obj2(10,20);
A obj3;
a) A(int y, int x)
b) A(int y; int x)
c) A(int y)
d) A(int x)
View Answer
Answer: a
Explanation: The two argument constructor will be called as we are passing 2 arguments to the
object while creation. The arguments will be passed together and hence compiler resolves that two
argument constructor have to be called.
Answer: b
Explanation: The constructors must contain only the class name. The class name is followed by the
blank parenthesis or we can have parameters if some values are to be passed.
Answer: c
Explanation: The destructor is never called in this situation. The concept is that when an object is
passed by reference to the function, the constructor is not called, but only the main object will be
used. Hence no destructor will be called at end of function.
26. Which access specifier is usually used for data members of a class?
a) Protected
b) Private
c) Public
d) Default
View Answer
Answer: b
Explanation: All the data members should be made private to ensure the highest security of data. In
special cases we can use public or protected access, but it is advised to keep the data members
private always.
Answer: d
Explanation: The data members can never be called directly. Dot operator is used to access the
members with help of object of class. Arrow is usually used if pointers are used.
Answer: a
Explanation: Using inheritance we can have the security of the class being inherited. The subclass
can access the members of parent class. And have more feature than a nested class being used.
29. Which keyword among the following can be used to declare an array of objects in java?
a) allocate
b) arr
c) new
d) create
View Answer
Answer: c
Explanation: The keyword new can be used to declare an array of objects in java. The syntax must
be specified with an object pointer which is assigned with a memory space containing the required
number of object space. Even initialization can be done directly.
30. Which operator can be used to free the memory allocated for an object in C++?
a) Unallocate
b) Free()
c) Collect
d) delete
View Answer
Answer: d
Explanation: The delete operator in C++ can be used to free the memory and resources held by an
object. The function can be called explicitly whenever required. In C++ memory management must
be done by the programmer. There is no automatic memory management in C++.
Answer: b
Explanation: The names are not property of an object. The identity can be in any form like address
or name of object but name can’t be termed as only identity of an object. The objects contain
attributes that define what type of data an object can store.
32. Which type of members can’t be accessed in derived classes of a base class?
a) All can be accessed
b) Protected
c) Private
d) Public
View Answer
Answer: c
Explanation: The private members can be accessed only inside the base class. If the class is
derived by other classes. Those members will not be accessible. This concept of OOP is made to
make the members more secure.
Answer: a
Explanation: It can only be indicated by using the data and functions that we use in derived class,
being provided by parent class. Copying code is nowhere similar to this concept, also using the
code already written is same as copying. Using already defined functions is not inheritance as we
are not adding any of our own features.
Answer: d
Explanation: The runtime inheritance is done when object of a class is created to call a method. At
runtime the function is searched if it is in class of object. If not, it will search in its parent classes
and hierarchy for that method.
Answer: c
Explanation: The virtual keyword is used to declare virtual functions. Anonymous keyword is used
with classes and have a different meaning. The virtual functions are used to call the intended
function of the derived class.
37. What happens if non static members are used in static member function?
a) Executes fine
b) Compile time error
c) Executes if that member function is not used
d) Runtime error
View Answer
Answer: b
Explanation: There must be specific memory space allocated for the data members before the
static member functions uses them. But the space is not reserved if object is not declared. Hence
only if static members are not used, it leads to compile time error.
Answer: a
Explanation: A non-member function of a class which can access even the private data of a class is
a friend function. It is an exception on access to private members outside the class. It is sometimes
considered as a member functions since it has all the access that a member function in general
have.
Answer: c
Explanation: The member function which is defined in base class and again in the derived class, is
overridden by the definition given in the derived class. This is because the preference is given more
to the local members. When derived class object calls that function, definition from the derived
class is used.
Answer: b
Explanation: Abstraction is hiding the complex code. For example, we directly use cout object in
C++ but we don’t know how is it actually implemented. Encapsulation is data binding, as in, we try
to combine a similar type of data and functions together.
Answer: a
Explanation: The polymorphism feature is exhibited by function overriding. Polymorphism is the
feature which basically defines that same named functions can have more than one functionalities.
Answer: d
Explanation: Even the private member functions can be called outside the class. This is possible if
address of the function is known. We can use the address to call the function outside the class.
Answer: c
Explanation: The keyword used to declare static variables is static. This is must be used while
declaring the static variables. The compiler can make variables static if and only if they are
mentioned with static keyword.
Answer: b
Explanation: The syntax must contain * symbol after the className as the type of object. This
declares an object pointer. This can store address of any object of the specified class.
46. Which class/set of classes can illustrate polymorphism in the following C++ code?
calc_grade();
public : calc_grade()
return 10;
};
public : calc_grade()
return 20;
};
Answer: d
Explanation: Since Student class is abstract class and class topper and average are inheriting
student, class topper and average must define the function named calc_grade(); in abstract class.
Since both the definition are different in those classes, calc_grade() will work in different way for
same input from different objects. Hence it shows polymorphism.
47. If data members are private, what can we do to access them from the class object?
a) Private data members can never be accessed from outside the class
b) Create public member functions to access those data members
c) Create private member functions to access those data members
d) Create protected member functions to access those data members
View Answer
Answer: b
Explanation: We can define public member functions to access those private data members and
get their value for use or alteration. They can’t be accessed directly but is possible to be access
using member functions. This is done to ensure that the private data doesn’t get modified
accidentally.
48. Which among the following is not a necessary condition for constructors?
a) Its name must be same as that of class
b) It must not have any return type
c) It must contain a definition body
d) It can contains arguments
View Answer
Answer: c
Explanation: Constructors are predefined implicitly, even if the programmer doesn’t define any of
them. Even if the programmer declares a constructor, it’s not necessary that it must contain some
definition.
Answer: d
Explanation: This is mandatory to pass the object by reference. Otherwise, the object will try to
create another object to copy its values, in turn a constructor will be called, and this will keep on
calling itself. This will cause the compiler to give out of memory error.
50. If in multiple inheritance, class C inherits class B, and Class B inherits class A. In which
sequence are their destructors called if an object of class C was declared?
a) ~A() then ~B() then ~C()
b) ~C() then ~A() then ~B()
c) ~C() then ~B() then ~A()
d) ~B() then ~C() then ~A()
View Answer
Answer: c
Explanation: The destructors are always called in the reverse order of how the constructors were
called. Here class A constructor would have been created first if Class C object is declared. Hence
class A destructor is called at last.
Answer: b
Explanation: Instance of abstract class can’t be created as it will not have any constructor of its
own, hence while creating an instance of class, it can’t initialize the object members. Actually the
class inheriting the abstract class can have its instance because it will have implementation of all
members.
Answer: a
Explanation: Virtual Functions can be defined in any class using the keyword virtual. All the classes
which inherit the class containing the virtual function, define the virtual function as required.
Redefining the function on all the derived classes according to class and use represents
polymorphism.
53. Which feature in OOP is used to allocate additional functions to a predefined operator in any
language?
a) Function Overloading
b) Function Overriding
c) Operator Overloading
d) Operator Overriding
View Answer
Answer: c
Explanation: The feature is operator overloading. There is not a feature named operator overriding
specifically. Function overloading and overriding doesn’t give addition function to any operator.