wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Programming Concepts: Procedural vs Object-Oriented Programming

Total questions: 50

Worksheet time: 1hrs 15mins

Name
Class
Date
1.

Which of the following is a major limitation of procedural programming?

a)

It promotes data security

b)

It allows data and functions to be linked together

c)

It focuses on functions, not data, leading to poor data security

d)

It supports code reusability through inheritance

2.

Why is Object-Oriented Programming (OOP) needed?

a)

To make programs longer and more complex

b)

To avoid using functions

c)

To structure programs around data and objects for better reusability and security

d)

To reduce the number of variables used

3.

In Object-Oriented Programming, an object is best described as:

a)

A collection of unrelated variables

b)

A real-world entity containing data and behavior

c)

Only a function

d)

A class definition

4.

What is data encapsulation?

a)

Hiding implementation details and combining data with methods in a single unit

b)

Allowing free access to data

c)

Dividing data and functions into separate blocks

d)

Using inheritance to access private data

5.

Data abstraction refers to:

a)

Displaying all the details of an object

b)

Showing only essential features while hiding internal details

c)

Writing long programs

d)

Overloading operators

6.

Which feature of OOP allows an object to take on many forms?

a)

Encapsulation

b)

Polymorphism

c)

Abstraction

d)

Inheritance

7.

What is inheritance in OOP?

a)

A. A mechanism where one class acquires properties of another class

b)

B. A process of hiding data from other classes

c)

C. A method for overloading functions

d)

D. A process to convert data types

8.

The process of linking a function call to its definition at runtime is known as:

a)

Static binding

b)

Dynamic binding

c)

Encapsulation

d)

Overloading

9.

In OOP, message passing refers to:

a)

Sending data directly to variables

b)

Calling methods of an object using object references

c)

Sharing memory between objects

d)

Transferring code between files

10.

Which access modifier allows a class member to be accessed only within the same class?

a)

Public

b)

Protected

c)

Private

d)

Default

11.

Which of the following correctly defines a method in a class?

a)

A variable declared inside a class

b)

A block of code that performs a specific task and belongs to a class

c)

A comment inside the program

d)

A data type used in a class

12.

What is the purpose of the this keyword in Java?

a)

To refer to the parent class

b)

To refer to the current object of the class

c)

To refer to the child class

d)

To refer to a static method

13.

3. Method overloading means:

a)

defining multiple methods with the same name but different parameters

b)

defining multiple methods with the same name and same parameters

c)

defining methods with different names but same parameters

d)

defining methods with different names and different parameters

14.

Which keyword is used to allocate memory for an object in Java?

a)

malloc

b)

alloc

c)

new

d)

create

15.

What are static data members?

a)

Variables that are local to a function

b)

Variables that belong to each object separately

c)

Variables shared by all objects of the class

d)

Variables that cannot be initialized

16.

What is the main purpose of a constructor?

a)

To destroy objects

b)

To initialize objects when they are created

c)

To overload methods

d)

To store constant values

17.

Which of the following is not true about constructors?

a)

A. A constructor has the same name as the class

b)

B. A constructor has no return type

18.

What is constructor overloading?

a)

Having multiple constructors in a class with different parameter lists

b)

Having multiple destructors in a class

c)

Using inheritance to create constructors

d)

Declaring static constructors

19.

What is garbage collection in Java?

a)

Process of manually freeing memory using delete keyword

b)

Process of automatic memory management that removes unused objects

c)

Process of sorting data

d)

Process of creating arrays

20.

What is a destructor or finalizer used for?

a)

To initialize data members

b)

To allocate memory

c)

To perform cleanup operations before an object is destroyed

d)

To overload constructors

21.

What is inheritance in Object-Oriented Programming?

a)

The process of creating multiple objects from one class

b)

The process where one class acquires the properties and behaviors of another class

c)

The process of hiding data

d)

The process of linking functions dynamically

22.

What is inheritance in object-oriented programming?

a)

The process of hiding data from users

b)

The process where one class acquires the properties and behaviors of another class

c)

The process of creating objects

d)

The process of restricting the use of objects

23.

Which of the following best describes the need for inheritance?

a)

To hide data from users

b)

To improve code reusability and avoid redundancy

c)

To reduce the number of classes in a program

d)

To restrict the use of objects

24.

Which type of inheritance allows a class to inherit from more than one base class?

a)

Single inheritance

b)

Multiple inheritance

c)

Multilevel inheritance

d)

Hybrid inheritance

25.

What is the main benefit of using inheritance?

a)

Increases data redundancy

b)

Simplifies maintenance and promotes code reusability

c)

Makes debugging more difficult

d)

Prevents method overriding

26.

What is method overriding?

a)

Writing two methods with the same name but different parameters in the same class

b)

Redefining a method of a parent class in the derived class with the same signature

c)

Overloading constructors

d)

Writing a static method inside a class

27.

What happens when a derived class object is created in Java regarding constructors?

a)

Only the derived class constructor is called

b)

Only the base class constructor is called

c)

Base class constructor is called first, then derived class constructor

d)

Constructors are not called automatically

28.

Which of the following statements about abstract classes is true?

a)

Abstract classes can be instantiated directly

b)

Abstract classes can contain abstract and non-abstract methods

c)

Abstract classes cannot have constructors

d)

Abstract methods must have a body

29.

What is an interface primarily used for?

a)

To store constants

b)

To provide a blueprint for classes by defining method signatures without implementation

c)

To hide data members

d)

To create objects directly

30.

Which of the following is an example of compile-time polymorphism?

a)

Method overriding

b)

Method overloading

c)

Dynamic binding

d)

Interface implementation

31.

How does polymorphism improve software reuse?

a)

By allowing objects of different classes to be treated as objects of a common superclass

b)

By restricting inheritance

c)

By avoiding the use of abstract classes

d)

By increasing the number of classes needed

32.

What will be the output of the following code? try { int a = 10 / 0; System.out.println("Inside try block"); } catch (ArithmeticException e) { System.out.println("Exception caught"); } System.out.println("Program continues...");

a)

Inside try block

b)

Exception caught

c)

Program continues...

d)

Both B and C

33.

What will happen if no catch block matches the thrown exception?

a)

Program runs successfully

b)

The JVM terminates the program with an error message

c)

The exception is ignored

d)

The exception is converted into a warning

34.

try { int x = 5 / 0; } catch (ArithmeticException e) { System.out.println("Inner catch"); } catch (Exception e) { System.out.println("Outer catch"); }

a)

Inner catch

b)

Outer catch

c)

Both Inner and Outer catch

d)

No output

35.

What will be the output?

a)

Index error

b)

General error

c)

Both

d)

No output

36.

What is the output of this code using Generics?

a)

[10, 20, Hello]

b)

Compilation error at Line X

c)

Runtime error

d)

No output

37.

Which of the following correctly defines a generic method?

a)

public void display(T data) { }

b)

public void display(T data) { }

c)

public void display(T data) { }

38.

What is the output of this program? List names = new ArrayList<>(); names.add("Alice"); names.add("Bob"); names.add("Charlie"); System.out.println(names.get(1));

a)

Alice

b)

Bob

c)

Charlie

d)

null

39.

What happens if you try to remove a non-existent element from a set in Java?

a)

Throws Exception

b)

Prints [A]

c)

Prints []

d)

Compilation error

40.

What will the following code print? LinkedList nums = new LinkedList<>(); nums.add(5); nums.add(10); nums.addFirst(2); System.out.println(nums);

a)

[2, 5, 10]

b)

[5, 10, 2]

c)

[10, 5, 2]

d)

[2, 10, 5]

41.

A. [5, 10, 2] B. [2, 5, 10] C. [10, 5, 2] D. [2, 10, 5]

a)

A. [5, 10, 2]

b)

B. [2, 5, 10]

c)

C. [10, 5, 2]

d)

D. [2, 10, 5]

42.

What is the main purpose of streams in Java file handling?

a)

To create GUI applications

b)

To transfer data between source and destination

c)

To store data permanently

d)

To execute SQL queries

43.

Which of the following classes is used for byte stream input in Java?

a)

FileReader

b)

FileWriter

c)

FileInputStream

d)

BufferedReader

44.

Which stream class is used for reading characters from a file?

a)

FileInputStream

b)

FileReader

c)

ObjectInputStream

d)

DataInputStream

45.

The File class in Java is used to:

a)

Read data from a file

b)

Write data to a file

46.

Which of the following is true about Random Access File?

a)

It allows only sequential access

b)

It allows both read and write operations at any position in the file

c)

It can read only text files

d)

It is used for networking

47.

Which exception is thrown during input/output operations if an error occurs?

a)

IOException

b)

ArithmeticException

c)

NullPointerException

d)

FileException

48.

Which class allows buffered reading and writing for better performance?

a)

DataInputStream

b)

BufferedReader and BufferedWriter

c)

ObjectOutputStream

d)

PrintStream

49.

The Singleton design pattern ensures that:

a)

Multiple instances of a class can be created

b)

Only one instance of a class exists throughout the application

c)

No instances of a class can be created

d)

The class can be inherited

50.

What is the purpose of the Adapter design pattern?

a)

To add new functionality dynamically

b)

To allow incompatible interfaces to work together

c)

To manage object creation

d)

To provide global access to data