Object Oriented Programming Questions and Answers - Classes: Student
Object Oriented Programming Questions and Answers - Classes: Student
Classes
This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers
(MCQs) focuses on “Classes”.
11. Which among the following is false, for member function of a class?
a) All member functions must be defined
b) Member functions can be defined inside or outside the class body
c) Member functions need not be declared inside the class definition
d) Member functions can be made friend to another class using friend keyword
View Answer
Answer: c
Explanation: Member functions must be declared inside class body, thought the definition can be
given outside the class body. There is no way to declare the member functions inside the class.
12. Which syntax for class definition is wrong?
a) class student{ };
b) student class{ };
c) class student{ public: student(int a){ } };
d) class student{ student(int a){} };
View Answer
Answer: b
Explanation: Keyword class should come first. Class name should come after keyword class.
Parameterized constructor definition depends on programmer so it can be left empty also.
13. Which of the following pairs are similar?
a) Class and object
b) Class and structure
c) Structure and object
d) Structure and functions
View Answer
Answer: b
Explanation: Class and structure are similar to each other. Only major difference is that a structure
doesn’t have member functions whereas the class can have both data members and member
functions.
14. Which among the following is false for class features?
a) Classes may/may not have both data members and member functions
b) Class definition must be ended with a colon
c) Class can have only member functions with no data members
d) Class is similar to union and structures
View Answer
Answer: b
Explanation: Class definition must end with a semicolon, not colon. Class can have only member
functions in its body with no data members.
15. Instance of which type of class can’t be created?
a) Anonymous class
b) Nested class
c) Parent class
d) Abstract class
View Answer
Answer: d
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.