Oops - placement practice test

Oops - placement practice test


1. By default, members of the class are____________ in nature.

a. protected
b. private
c. public
d. static
View Answer / Hide Answer

ANSWER: b. private
Explanation: If access specifier is not written/specified, in that case all members of the class are private in nature by CPP conventions.




2. Private members of the class are accessible only to the members of the same class.

a. True
b. False
View Answer / Hide Answer

ANSWER: b. False
Explanation: It is not compulsion or mandatory that all private members of the class are accessible only to the members of that class. We can have access to private members of the class

through friend function which is neither in the scope of that class and nor a member function of that class.




3. public data members and member functions of the class are accessible ONLY to the member functions of that class.

a. True
b. False
View Answer / Hide Answer

ANSWER: b. False
Explanation: This statement is false as public members of the class are accessible to the other parts of the program as well. They are accessible to the objects of the other classes in the

same application through friend functions or friend classes.




4. class TEST
{
private:
int roll_no;
public:
int age;
char name[20];
private:
int grade;
protected:
char gender[20];
private:

private:
int m1, m2, m3;
};

In general view, is this class definition valid?

a. Yes
b. No
View Answer / Hide Answer

ANSWER: a. Yes
Explanation: This kind of class declaration is not a standard or good practice as multiple types we are specifying access specifiers. But still, this program smoothly runs as we can write

access specifiers multiple times inside the class in any order or even simultaneously.




5. Members of the class can be declared with auto, extern or register storage classes.

a. True
b. False
View Answer / Hide Answer

ANSWER: b. False
Explanation: No member of the class can be declared with auto, extern or register storage class. If you do so, you will be issued with warning “Storage class ‘register’ is not allowed here”.
But members of the class can be declared as static.




6. C structure differs from CPP class in regards that by default all the members of the structure are__________ in nature.

a. private
b. protected
c. public
d. None of these
View Answer / Hide Answer

ANSWER: c. public




7. In CPP program, Can we declare and define a user defined function inside a struct as we do in a class ?

a. Yes
b. No
c. Can’t say
View Answer / Hide Answer

ANSWER: a. Yes
Explanation: Just like a class, we can declare and define a user defined function inside the struct and able to access the same by the structure variable with dot relationship.




8. ____________ refers to the act of representing only essential features without including the background details.

a. Data Hiding
b. Data Encapsulation
c. Data Abstraction
d. All of these
View Answer / Hide Answer

ANSWER: c. Data Abstraction




9. Only functions of the class can access the data of the class and they(functions) provides the interface between data, objects and the program. This kind isolation of the data from direct

access by the program is called_______________

a. Data Abstraction
b. Data Hiding
c. Data Binding
d. Data Encapsulation
View Answer / Hide Answer

ANSWER: b. Data Hiding




10. __________________ is the OOP feature and mechanism that binds together code and the data it manipulates, and keep both safe from outside world.

a. Data Binding
b. Data Encapsulation
c. Data Storing
d. Data Abstraction
View Answer / Hide Answer

ANSWER: b. Data Encapsulation




11. Object based language differs from Object oriented language as it does not support features

1. Encapsulation
2. Inheritance
3. Dynamic Binding
4. Abstraction
5. Polymorphism

a. only 3 ,4
b. only 1,3,5
c. 2,4,5
d. only 2,3
View Answer / Hide Answer

ANSWER: d. only 2,3




12. Object oriented programming employs_________ programming approach.

a. top-down
b. procedural
c. bottom-up
d. all of these.
View Answer / Hide Answer

ANSWER: c. bottom-up




13. In CPP, cin and cout are the predefined stream__________

a. Operator
b. Functions
c. Objects
d. Data types
View Answer / Hide Answer

ANSWER: c. Objects




14. Classes in CPP are________

a.derived data types
b.User defined data types
c.built-in data types
d. All of these
View Answer / Hide Answer

ANSWER: b.User defined data types




15. In CPP, it is mandatory and must to initialize const variables.

a. True
b. False
View Answer / Hide Answer

ANSWER: a. True
Explanation: The answer is True. In order to have constant variables in CPP using const qualifier, they are need to be declared and defined on the same line i.e. declaration with

initialization is must. Try following code in Turbo CPP editor or any CPP editor/compiler.

int main()
{
const int x; //this statement will cause error
const int y=100; //this statement is valid
cout<<“ value of y==”<<y;
return 0;
}




16. Constant variables can be created in CPP by using________

a. enum
b. const
c. #define
d. All of these
e. None of these
View Answer / Hide Answer

ANSWER: d. All of these




17. Which of the followings is/are not keyword/s in CPP?

1. asm
2. boolean
3. mutable
4. export
5. constant_cast

a. Only 5
b. Only 1 and 4
c. Only 1,2 and 5
d. Only 2 and 5
View Answer / Hide Answer

ANSWER: d. Only 2 and 5




18. Can a class be declared/defined inside another class ?

a. Yes
b. No
View Answer / Hide Answer

ANSWER: a. Yes
Explanation: Like nested structure in C, we can have nested classes in CPP.




19. When a class is defined inside any function or block, it is called_____________

a. Nested class
b. Block class
c. Local class
d. It is not possible
View Answer / Hide Answer

ANSWER: c. Local class




20. The CPP compiler supports automatic type conversions for the user defined data types.

a. True
b. False
View Answer / Hide Answer

ANSWER: b. False




21. Which of the followings are false statements about Local class?

1. A local class type name can only be used in the enclosing function
2. All the methods of Local classes must be defined inside the class only
3. A Local class can contain static data members.
4. A Local class may contain static functions.
5. Non-static variables of the enclosing function are not accessible inside local classes.
6. Local classes cannot access global types, variables and functions.

a. Only 1,3
b. Only 3, 6
c. Only 2 , 4 , 6
d. None of these
View Answer / Hide Answer

ANSWER: b. Only 3, 6



Post your comment