0% found this document useful (0 votes)
84 views9 pages

Answers

This document contains 20 multiple choice questions about object-oriented programming concepts in Java such as data types, access specifiers, polymorphism, inheritance, encapsulation, and classes and objects. It provides the question, possible answers, the correct answer, and a short explanation for each question. The questions cover OOP concepts like the smallest integer type in Java, what features demonstrate polymorphism, which feature enables code reusability, the types of access specifiers, the definition of encapsulation, and how classes and objects relate to each other.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views9 pages

Answers

This document contains 20 multiple choice questions about object-oriented programming concepts in Java such as data types, access specifiers, polymorphism, inheritance, encapsulation, and classes and objects. It provides the question, possible answers, the correct answer, and a short explanation for each question. The questions cover OOP concepts like the smallest integer type in Java, what features demonstrate polymorphism, which feature enables code reusability, the types of access specifiers, the definition of encapsulation, and how classes and objects relate to each other.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1. Which of the following is smallest integer data type ?

A. int

B. byte

C. short

D. long

View Answer

Ans : B

Explanation: smallest integer data type is Byte.

2. Q) What concepts come under Polymorphism in java?

1. Method overloading
2. Constructor overloading
3. Method overriding
4. All the above

Answer: 4

Explanation: All mentioned features come under polymorphism in java oop.

● Method overloading (multiple methods with same name in a class)


● Constructor overloading (multiple constructors in a class)
● Method overriding (methods with same in base and derived class)

3. 5. Which feature of OOP indicates code reusability?


a) Abstraction
b) Polymorphism

c) Encapsulation

d) Inheritance

View Answer

Answer: d

Explanation: Inheritance indicates the code reusability. Encapsulation and abstraction are meant to
hide/group data into one element. Polymorphism is to indicate different tasks performed by a single
entity.

4. How many types of access specifiers are provided in OOP (C++)?


a) 4

b) 3

c) 2

d) 1

View Answer

Answer: b

Explanation: Only 3 types of access specifiers are available. Namely, private, protected and public. All
these three can be used according to the need of security of members

5. What is encapsulation in OOP?


a) It is a way of combining various data members and member functions that operate on those data
members into a single unit

b) It is a way of combining various data members and member functions into a single unit which can
operate on any data
c) It is a way of combining various data members into a single unit

d) It is a way of combining various member functions into a single unit

View Answer

Answer: a

Explanation: It is a way of combining both data members and member functions, which operate on
those data members, into a single unit. We call it a class in OOP generally. This feature have helped us
modify the structures used in C language to be upgraded into class in C++ and other languages.

6. Which of the following data types comes under floating data types ?
A. int

B. double

C. long

D. byte

View Answer

Ans : B

Explanation: Floating-point numbers includes float and double

7.Which type of members can’t be accessed in derived classes of a base class?


a) All can be accessed

b) Protected

c) Private

d) Public

View Answer

Answer: c
Explanation: The private members can be accessed only inside the base class. If the class is derived by
other classes. Those members will not be accessible. This concept of OOP is made to make the
members more secure.

8. Which feature of OOP is exhibited by the function overriding?


a) Polymorphism

b) Encapsulation

c) Abstraction

d) Inheritance

View Answer

Answer: a

Explanation: The polymorphism feature is exhibited by function overriding. Polymorphism is the


feature which basically defines that same named functions can have more than one functionalities

9. Java does not support _______________?

1. Inheritance
2. Multiple inheritance for classes
3. multiple inheritance of interfaces
4. compile time polymorphism

Answer: 2

Java does not support multiple inheritance for classes but in java multiple inheritance behavior is
implemented using interfaces.

10. Runtime polymorphism feature in java is


1. method overriding
2. method overloading
3. constructor overloading
4. operator overloading

Answer: 1

Since in method overriding both the classes(base class and child class) have same method, compile
doesn’t figure out which method to call at compile-time. In this case JVM(java virtual machine) decides
which method to call at runtime that’s why it is known as runtime or dynamic polymorphism.

11. IS-A relationship in java is related to

1. Inheritance
2. Encapsulation
3. Composition
4. None

Answer: 1

12. Which is not feature of OOP in general definitions?


a) Code reusability

b) Modularity

c) Duplicate/Redundant data

d) Efficient Code

View Answer

Answer: c
Explanation: Duplicate/Redundant data is dependent on programmer and hence can’t be guaranteed
by OOP. Code reusability is done using inheritance. Modularity is supported by using different code
files and classes. Codes are more efficient because of features of OOP

13. 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.

14. 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.

15. f a function can perform more than 1 type of tasks, where the function name remains same, which
feature of OOP is used here?
a) Encapsulation

b) Inheritance

c) Polymorphism

d) Abstraction

View Answer

Answer: c

Explanation: For the feature given above, the OOP feature used is Polymorphism. Example of
polymorphism in real life is a kid, who can be a student, a son, a brother depending on where he is.

16. Which of the following best defines a class?


a) Parent of an object

b) Instance of an object

c) Blueprint of an object

d) Scope of an object

View Answer

Answer: c
Explanation: A class is Blueprint of an object which describes/ shows all the functions and data that
are provided by an object of a specific class. It can’t be called as parent or instance of an object. Class
in general describes all the properties of an object.

17. Why Java is Partially OOP language?


a) It supports usual declaration of primitive data types

b) It doesn’t support all types of inheritance

c) It allows code to be written outside classes

d) It does not support pointers

View Answer

Answer: a

Explanation: As Java supports usual declaration of data variables, it is partial implementation of OOP.
Because according to rules of OOP, object constructors must be used, even for declaration of
variables.

18. Class is _________ abstraction.


a) Object

b) Logical

c) Real

d) Hypothetical

View Answer

Answer: b

Explanation: Class is logical abstraction because it provides a logical structure for all of its objects. It
gives an overview of the features of an object.
19. Object is ________ abstraction.
a) Object

b) Logical

c) Real

d) Hypothetical

View Answer

Answer: c

Explanation: Object is real abstraction because it actually contains those features of class. It is the
implementation of overview given by class. Hence the class is logical abstraction and its object is real.

20. Which definition best describes an object?


a) Instance of a class

b) Instance of itself

c) Child of a class

d) Overview of a class

View Answer

Answer: a

Explanation: An object is instance of its class. It can be declared in the same way that a variable is
declared, only thing is you have to use class name as the data type.

You might also like