wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

OOP Concepts in Java_Revision

Total questions: 30

Worksheet time: 30mins

Name
Class
Date
1.

What is a class in object-oriented programming?

a)

A class is a collection of data without methods.

b)

A class is a blueprint for creating objects that defines properties and methods.

c)

A class is a function that executes code.

d)

A class is a type of variable in programming.

2.

Which of the following is an example of an object?

a)

A table

b)

A chair

c)

A car

d)

A computer

3.

What is the purpose of a constructor in a class?

a)

The purpose of a constructor in a class is to initialize objects.

b)

To create static variables in a class.

c)

To delete objects from memory.

d)

To define methods in a class.

4.

How do you clone an object in Java?

a)

Use the copy constructor method.

b)

Implement the Cloneable interface and use the clone() method.

c)

Call the Object.copy() method.

d)

Serialize the object to a file.

5.

What method is used to create a copy of an object?

a)

replicate function

b)

copy constructor

c)

duplicate method

d)

clone or copy method

6.

What is single inheritance?

a)

Single inheritance is when a class inherits from one and only one parent class.

b)

Single inheritance allows multiple parent classes.

c)

Single inheritance is when a class inherits from no parent class.

d)

Single inheritance is a feature of functional programming only.

7.

What is multiple inheritance?

a)

Single inheritance from one parent class

b)

Inheritance that allows classes to share methods only

c)

Multiple inheritance is when a class can inherit from multiple parent classes.

d)

A method of combining multiple classes into one

8.

Which keyword is used to inherit a class in Java?

a)

implements

b)

inherits

c)

subclass

d)

extends

9.

What is an interface in Java?

a)

An interface is a collection of objects that can be instantiated.

b)

An interface is a class that can contain method implementations.

c)

An interface in Java is a reference type that defines a contract for classes to implement.

d)

An interface is a type of variable that holds data.

10.

How do you implement an interface in a class?

a)

Use the 'inherits' keyword to implement an interface.

b)

Define interface methods without implementing them.

c)

Use the 'extends' keyword in the class declaration.

d)

Use the 'implements' keyword in the class declaration and define all interface methods.

11.

What is the purpose of generic classes in Java?

a)

To improve the performance of Java applications.

b)

To restrict the use of primitive data types in Java.

c)

To simplify the syntax of Java code.

d)

The purpose of generic classes in Java is to enable type-safe operations on different data types while promoting code reusability.

12.

How do you define a generic method?

a)

A method that only works with integers.

b)

A method that cannot take any parameters.

c)

A method that is specific to one data type.

d)

A method that can operate on different data types specified by type parameters.

13.

What is polymorphism in programming?

a)

Polymorphism refers to the process of compiling code into machine language.

b)

Polymorphism is a method of optimizing memory usage in programming.

c)

Polymorphism is the ability of different classes to be treated as instances of the same class through a common interface.

d)

Polymorphism is the ability to create multiple instances of a class.

14.

What is method overloading?

a)

Method overloading is the ability to change the name of a method in a class.

b)

Method overloading is when a method can be called with any number of parameters.

c)

Method overloading is the ability to define multiple methods with the same name but different parameters in a class.

d)

Method overloading refers to the process of overriding a method in a subclass.

15.

What is method overriding?

a)

Method overriding is a feature in object-oriented programming where a subclass redefines a method from its superclass.

b)

Method overriding is a way to hide methods in a subclass without changing their implementation.

c)

Method overriding is a technique to create multiple methods with the same name in a class.

d)

Method overriding is when a superclass redefines a method from its subclass.

16.

How does Java achieve runtime polymorphism?

a)

Java achieves runtime polymorphism through method overloading.

b)

Java achieves runtime polymorphism through method overriding.

c)

Java achieves runtime polymorphism by using interfaces only.

d)

Java achieves runtime polymorphism via static binding.

17.

What is the difference between an abstract class and an interface?

a)

An abstract class cannot have any methods, while an interface can have implemented methods.

b)

An abstract class can only be instantiated, while an interface cannot be instantiated.

c)

An abstract class can implement multiple interfaces, while an interface cannot extend an abstract class.

d)

An abstract class can have implemented methods and state, while an interface cannot.

18.

What is the significance of the 'instanceof' operator?

a)

The 'instanceof' operator is used to compare two strings.

b)

The 'instanceof' operator creates a new instance of an object.

c)

The 'instanceof' operator checks if a variable is undefined.

d)

The 'instanceof' operator checks the prototype chain of an object to determine if it is an instance of a specified constructor.

19.

How can you create a generic class in Java?

a)

Generic classes cannot have constructors.

b)

You create a generic class by extending another class.

c)

You create a generic class in Java by using type parameters, e.g., 'class MyClass { }'.

d)

You can only create a generic class with interfaces.

20.

What is the role of reflection in Java?

a)

Reflection is used for compiling Java code.

b)

Reflection in Java is used for inspecting and manipulating classes, methods, and fields at runtime.

c)

Reflection allows for static type checking at compile time.

d)

Reflection is a method for optimizing Java performance.

21.

What is the purpose of encapsulation in object-oriented programming?

a)

Encapsulation is used to hide the internal state of an object and require all interaction to be performed through an object's methods.

b)

Encapsulation allows multiple classes to share the same methods.

c)

Encapsulation is a way to create static methods in a class.

d)

Encapsulation is the process of combining multiple classes into one.

22.

What is the difference between a class and an object?

a)

A class is a collection of objects, while an object is a single instance of a class.

b)

A class can only contain methods, while an object can only contain data.

c)

A class is a type of variable, while an object is a function.

d)

A class is a blueprint for creating objects, while an object is an instance of a class.

23.

What is the significance of the 'super' keyword in Java?

a)

The 'super' keyword is used to implement interfaces.

b)

The 'super' keyword is used to define static methods in a class.

c)

The 'super' keyword is used to create a new instance of a class.

d)

The 'super' keyword is used to refer to the superclass of the current object.

24.

What is the purpose of the 'this' keyword in Java?

a)

'this' is used to refer to the superclass of the current object.

b)

'this' refers to the current object in a method or constructor.

c)

'this' is used to create a new instance of a class.

d)

'this' is a keyword for defining static methods.

25.

What is the difference between a constructor and a method?

a)

A constructor is called when an object is created, while a method is called to perform an action on an object.

b)

A constructor is always public, while a method can be private.

c)

A constructor is a type of variable, while a method is a type of class.

d)

A constructor can return a value, while a method cannot.

26.

What is the role of the 'final' keyword in Java?

a)

The 'final' keyword is used to implement interfaces.

b)

The 'final' keyword is used to define methods that can be overridden.

c)

The 'final' keyword is used to create abstract classes.

d)

The 'final' keyword is used to declare constants that cannot be changed.

27.

What is the purpose of inheritance in object-oriented programming?

a)

Inheritance is used to create multiple instances of a class.

b)

Inheritance allows a class to inherit properties and methods from another class.

c)

Inheritance is the process of combining multiple classes into one.

d)

Inheritance is a way to define static variables in a class.

28.

What does the 'abstract' keyword signify in a class declaration?

a)

The 'abstract' keyword indicates that a class cannot be instantiated and may contain abstract methods.

b)

The 'abstract' keyword allows a class to implement multiple interfaces.

c)

The 'abstract' keyword is used to define constants in a class.

d)

The 'abstract' keyword is used to create static methods.

29.

What is the role of the 'static' keyword in Java?

a)

The 'static' keyword is used to define methods that can be called without creating an instance of a class.

b)

The 'static' keyword is used to define abstract classes.

c)

The 'static' keyword allows a method to be overridden.

d)

The 'static' keyword is used to create instance variables.

30.

What is the significance of the 'volatile' keyword in Java?

a)

The 'volatile' keyword is used to define methods that cannot be overridden.

b)

The 'volatile' keyword is used to declare constants that can be changed.

c)

The 'volatile' keyword indicates that a variable's value will be modified by different threads.

d)

The 'volatile' keyword is used to create static variables.