Skip to content
GK24
Computer AwarenessMedium

Which special member function is executed automatically when an object of a class is created?

  1. A.Destructor
  2. B.Constructor
  3. C.Friend function
  4. D.Virtual function

Correct answer

B. Constructor

Explanation

The correct answer is B, Constructor. A constructor carries the same name as its class, is called automatically the moment an object is created and is normally used to give the data members their initial values; it returns no value at all, not even void, and it can be overloaded. Option A is wrong because the destructor is the mirror image, called automatically when the object is destroyed, and in C++ it is written with a tilde before the class name. Option C is wrong because a friend function is a non-member function given access to the private members of a class, and it has to be called like any other function. Option D is wrong because a virtual function is the C++ device for run-time polymorphism and is called through a base class pointer. Constructor on creation, destructor on destruction is the pair to memorise.

Read the full article: Object-Oriented Programming: Classes, Objects and Pillars

View all
Q3.Computer AwarenessEasy

Wrapping up of data and the functions that operate on that data into a single unit is called

  1. A.Inheritance
  2. B.Encapsulation
  3. C.Overloading
  4. D.Compilation
Show answer
Correct answer: B. Encapsulation

Encapsulation means binding the data members and the member functions that act on them inside one unit, the class, and keeping the data private so that it can be reached only through the methods provided; the standard illustration is a capsule holding the medicine inside it.

Read the full explanation →
Q4.Computer AwarenessMedium

Showing only the essential features of an object to the user while hiding its internal details is known as

  1. A.Abstraction
  2. B.Encapsulation
  3. C.Inheritance
  4. D.Instantiation
Show answer
Correct answer: A. Abstraction

Abstraction presents only what the user needs, such as the accelerator and brake of a car, and keeps the internal working out of sight; in C++ it is obtained through abstract classes with pure virtual functions and in Java through interfaces and abstract classes.

Read the full explanation →
Q5.Computer AwarenessEasy

Who developed the C++ programming language?

  1. A.Dennis Ritchie
  2. B.James Gosling
  3. C.Bjarne Stroustrup
  4. D.Guido van Rossum
Show answer
Correct answer: C. Bjarne Stroustrup

Bjarne Stroustrup developed the language at Bell Laboratories, starting it as C with Classes and giving it the name C++ in 1983; it adds classes, inheritance and polymorphism to C while keeping C procedural power, which is why it is called a hybrid language.

Read the full explanation →