πŸ“Š Object Oriented Programming (OOP)
Q. Which of the following statements is correct for a static member function?
1. It can access only other static members of its class.
ο‚· It can be called using the class name, instead of objects
  • (A) only 1 is correct
  • (B) only 2 is correct
  • (C) both 1 and 2 are correct
  • (D) both 1 and 2 are incorrect
πŸ’¬ Discuss
βœ… Correct Answer: (C) both 1 and 2 are correct
πŸ“Š Object Oriented Programming (OOP)
Q. 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
πŸ’¬ Discuss
βœ… Correct Answer: (A) compile-time error
πŸ“Š Object Oriented Programming (OOP)
Q. What is the difference between struct and class in C++?
  • (A) all members of a structure are public and structures don't have constructors and destructors
  • (B) members of a class are private by default and members of struct are public by default. when deriving a struct from a class/struct, default access-specifier for a base class/struct is public and when deriving a class, default access specifier is private.
  • (C) all members of a structure are public and structures don't have virtual functions
  • (D) all above
πŸ’¬ Discuss
βœ… Correct Answer: (B) members of a class are private by default and members of struct are public by default. when deriving a struct from a class/struct, default access-specifier for a base class/struct is public and when deriving a class, default access specifier is private.
πŸ“Š Object Oriented Programming (OOP)
Q. Predict the output of following C++ program
#include<iostream> using namespace std;
class Empty {}; int main()
{
cout <<sizeof(Empty); return 0;
}
  • (A) a non zero value
  • (B) 0
  • (C) compile time error
  • (D) runtime error
πŸ’¬ Discuss
βœ… Correct Answer: (A) a non zero value
πŸ“Š Object Oriented Programming (OOP)
Q. Which of the following is true?
  • (A) all objects of a class share all data members of class
  • (B) objects of a class do not share non-static members. every object has its own copy
  • (C) objects of a class do not share codes of non-static methods, they have their own copy
  • (D) none
πŸ’¬ Discuss
βœ… Correct Answer: (B) objects of a class do not share non-static members. every object has its own copy
πŸ“Š Object Oriented Programming (OOP)
Q. Which of the following is true about new when compared with malloc. 1) new is an operator, malloc is a function 2) new calls constructor, malloc doesn't 3) new returns appropriate pointer, malloc returns void * and pointer needs to typecast to appropriate type.
  • (A) 1 and 3
  • (B) 2 and 3
  • (C) 1 and 2
  • (D) all 1,2,3
πŸ’¬ Discuss
βœ… Correct Answer: (C) 1 and 2
πŸ“Š Object Oriented Programming (OOP)
Q. Predict the output?
#include <iostream> using namespace std;
class Test
{
int x;
Test() { x = 5;}
};
int main()
{
Test *t = new Test; cout <<t->x;
}
  • (A) compile time error
  • (B) garbage
  • (C) 0
  • (D) 5
πŸ’¬ Discuss
βœ… Correct Answer: (A) compile time error
πŸ“Š Object Oriented Programming (OOP)
Q. Is it fine to call delete twice for a pointer?
#include<iostream> using namespace std;
int main()
{
int *ptr = new int; delete ptr;
delete ptr; return 0;
}
  • (A) yes
  • (B) no
  • (C) ---
  • (D) ---
πŸ’¬ Discuss
βœ… Correct Answer: (B) no
πŸ“Š Object Oriented Programming (OOP)
Q. Which of the followings is/are automatically added to every class, if we do not write our own.
  • (A) copy constructor
  • (B) assignment operator
  • (C) a constructor without any parameter
  • (D) all
πŸ’¬ Discuss
βœ… Correct Answer: (D) all

Jump to