C++ Object Oriented Programming
This quiz covers fundamental concepts of Object Oriented Programming in C++, including classes, objects, inheritance, polymorphism, encapsulation, constructors, and access specifiers.
Questions
In an office, a clerk builds a logic using C++ to calculate salary of the employees, which is hidden from the other employees. Which feature of the language is he using?
- Inheritance
- Encapsulation
- Abstraction
- Class
- None of these
Which of the following is the correct syntax of declaring a class in C++?
- class classname {varibale declaration function declaration};
- class {variables; function;};
- class classname{variables function};
- class classname;{ };
- class classname {member variables; member function;}
Which of the following statements is incorrect about classes in object oriented programming?
- A class is a user defined data-type.
- A class provides mechanism to hold data and function at one place.
- It incorporates security in programming.
- The member of a class can be accessed by any function.
- A class is a logical concept. In real world, objects exist physically.
Identify the data member or the member variables in the above program.
class A
{
public: int a;
void display()
{
cout<<"Enter the value in a";
cin>>a;
}
};
void main()
{
A a1; a1.display();
getch();
}
- a1 is the data member of class A.
- a is the data member of class A.
- Display is the data member in class A.
- Both a and d together are data members in class A.
- None of these
A company launched a new car by adding or modifying some features in an existing car. Which feature of OOPS is implemented by the company?
- Inheritance
- Encapsulation
- Abstraction
- Operator overloading
- Public
Which of the following operators is used in C++ to implement operator overloading?
- Scope resolution operator
- Structure reference
- Ternary condition
- Size of
- Addition operator
Which of the followng statements is incorrect about private access specifiers in C++?
- It prevents the misuse of data.
- It provides security to the data member.
- It creates a boundary for the members of a class.
- The member which is declared privately can be accessed by any other function in a class.
- None of these
Which of the following statements is incorrect about objects in C++?
- An object is a type of a certain class.
- Objects are real world entities.
- Objects are not implemented in C++.
- Objects are used to invoke member function of a class.
- Objects use message passing to communicate with each other.
In the above program, which is/are the possible reason(s) for not generating the output?
Class A
{
public: void display()
{
printf("This is class A");
}
};
void main()
{
A a1; a1.display();
getch();
}
- Use of printf in class A
- C++ use cout<< operator to display the text on screen.
- Function definition can always be done outside the class.
- Function calling can be done by using the name of the function.
- Both (1) and (2)
How will you resolve ambiguity between functions in C++?
- C++ uses the scope resolution operator to resolve ambiguity between functions.
- C++ supports function overloading to resolve ambiguity.
- Each function is unique in C++.
- C++ does not provide any mechanism to resolve function ambiguity.
- Both (1) and (2)
A person creates a class with the name 'A' in C++. He wishes to use the features of this class in class B. Which syntax will he use to implement this?
- class B:public/protected/private A
- class B inherits class A
- class B extends A
- class B:class A
- class B inherited A
Name a function in C++ which provides initial values to the objects.
- Member function
- Friend function
- Constructor
- Destructor
- None of these
In which section of the program will you declare a friend function for the class?
- Private
- Public
- Outside class definition with keyword friend
- Inside class definition
- None of these
Which of the following error messages is/are displayed to the user if the user improperly writes a header file in the above program? (Turbo C++)
#include"iostrem.h"
#include"conio.h"
void main()
{
cout<<"hi";
getch();
}
- Unable to open include file iosteam.h
- Undefined symbol cout
- Both (1) and (2)
- The program will compile and execute normally.
- It will give a warning to the user.
How will you implement multiple inheritance in C++?
- class B, class C:public A
- class B:public A
class C:public A - class B:public C
class C:public A - Multiple inheritance is not supported in C++.
- class A:public B
class B:public A