100% found this document useful (1 vote)
898 views5 pages

Object Oriented Programming Questions and Answers - Classes: Student

This document contains 15 multiple choice questions about object-oriented programming concepts related to classes. Some key points covered include: - Classes are pass by reference while structures are pass by copy. - The default access specifier for class members is private if no other specifier is provided. - Abstract classes can have member functions declared but not implemented, requiring inheriting classes to provide implementations. - A friend class can access all private members of another class it is declared as a friend of.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
898 views5 pages

Object Oriented Programming Questions and Answers - Classes: Student

This document contains 15 multiple choice questions about object-oriented programming concepts related to classes. Some key points covered include: - Classes are pass by reference while structures are pass by copy. - The default access specifier for class members is private if no other specifier is provided. - Abstract classes can have member functions declared but not implemented, requiring inheriting classes to provide implementations. - A friend class can access all private members of another class it is declared as a friend of.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Object Oriented Programming Questions and Answers –

Classes
This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers
(MCQs) focuses on “Classes”.

1. Which of the following is not type of class?


a) Abstract Class
b) Final Class
c) Start Class
d) String Class
View Answer
Answer: c
Explanation: Only 9 types of classes are provided in general, namely, abstract, final, mutable,
wrapper, anonymous, input-output, string, system, network. We may further divide the classes into
parent class and subclass if inheritance is used.
2. Class is pass by _______
a) Value
b) Reference
c) Value or Reference, depending on program
d) Copy
View Answer
Answer: b
Explanation: Classes are pass by reference, and the structures are pass by copy. It doesn’t depend
on program.
3. What is default access specifier for data members or member functions declared within a
class without any specifier, in C++ ?
a) Private
b) Protected
c) Public
d) Depends on compiler
View Answer
Answer: a
Explanation: The data members and member functions are Private by default in C++ classes, if none
of the access specifier is used. It is actually made to increase the privacy of data.
4. Which is most appropriate comment on following class definition :
class Student
{
int a;
public : float a;
};

a) Error : same variable name can’t be used twice


b) Error : Public must come first
c) Error : data types are different for same variable
d) It is correct
View Answer
Answer: a
Explanation: Same variable can’t be defined twice in same scope. Even if the data types are
different, variable name must be different. There is no rule like Public member should come first or
last.
5. Which is known as generic class?
a) Abstract class
b) Final class
c) Template class
d) Efficient Code
View Answer
Answer: c
Explanation: Template classes are known to be generic classes because those can be used for any
data type value and the same class can be used for all the variables of different data types.
6. Size of a class is :
a) Sum of size of all the variables declared inside the class
b) Sum of size of all the variables along with inherited variables in the class
c) Size of largest size of variable
d) Classes doesn’t have any size
View Answer
Answer: d
Explanation: Classes doesn’t have any size, actually the size of object of the class can be defined.
That is done only when an object is created and its constructor is called.
7. Which class can have member functions without their implementation?
a) Default class
b) String class
c) Template class
d) Abstract class
View Answer
Answer: d
Explanation: Abstract classes can have member functions with no implementation, where the
inheriting subclasses must implement those functions.
8. Which of the following describes a friend class?
a) Friend class can access all the private members of the class, of which it is a friend
b) Friend class can only access protected members of the class, of which it is a friend
c) Friend class don’t have any implementation
d) Friend class can’t access any data member of another class but can use it’s methods
View Answer
Answer: a
Explanation: A friend class can access all the private members of another class, of which it is friend.
It is a special class provided to use when you need to reuse the data of a class but don’t want that
class to have those special functions.
9. What is scope of a class nested inside another class?
a) Protected scope
b) Private scope
c) Global scope
d) Depends on access specifier and inheritance used
View Answer
Answer: d
Explanation: It depends on the access specifier and the type of inheritance used with the class,
because if the class is inherited then the nested class can be used by subclass too, provided it’s not
of private type.
10. Class with main() function can be inherited (True/False)
a) True
b) False
View Answer
Answer: a
Explanation: The class containing main function can be inherited and hence the program can be
executed using the derived class names also in java.
advertisement

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.

You might also like