wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

OOPS MCQ

Total questions: 73

Worksheet time: 37mins

Name
Class
Date
1.

What is the main purpose of an abstract class in Java?

a)

To create a class that cannot be instantiated

b)

To provide a template for subclasses

c)

To implement multiple inheritance

d)

To allow the use of inner classes

2.

Which of the following keywords is used to define an abstract class?

a)

final

b)

abstract

c)

static

d)

virtual

3.

Which of the following statements about inheritance in Java is correct?

a)

A) A class can extend multiple classes

b)

B) A subclass inherits methods from its superclass

c)

C) Inheritance can only be achieved through interfaces

d)

D) Constructors are inherited by subclasses

4.

What is the purpose of the super keyword?

a)

To call the parent class constructor

b)

To reference the current class instance

c)

To define an abstract method

d)

To access private members of a superclass

5.

Which of the following is NOT a feature of an inner class?

a)

It can access members of its outer class

b)

It can have static members

c)

It can be private, public, or protected

d)

It can extend another class

6.

What is the result of using the equals() method in Java?

a)

It compares object references

b)

It compares object content

c)

It must be overridden in every class

d)

It compares class types

7.

Why is it important to override the hashCode() method when overriding equals()?

a)

To ensure unique object identity

b)

To maintain the general contract for hash tables

c)

To optimize memory usage

d)

To allow method overloading

8.

Which of the following is true about the Object class in Java?

a)

All classes inherit from Object

b)

Object class cannot be subclassed

c)

Object class provides no methods

d)

Object class has no constructors

9.

In Java, what is the visibility of a protected attribute?

a)

Accessible only within its own package

b)

Accessible only within subclasses

c)

Accessible within its own package and subclasses

d)

Accessible from anywhere

10.

The visibility of private attributes in Java is:

a)

Only within the same class

b)

Within the same package

c)

Accessible by subclasses

d)

Accessible from anywhere

11.

Which of the following best describes the accessibility of private attributes in Java?

a)

Accessible from anywhere

b)

Accessible only within the same class

c)

Accessible from subclasses

d)

Accessible within its own package

12.

Which of the following statements is true about multiple inheritance in Java?

a)

A) A class can implement multiple interfaces

b)

B) A class can extend multiple classes

c)

C) Multiple inheritance is allowed for classes and interfaces

d)

D) A class can inherit from multiple abstract classes

13.

What is the purpose of the instanceof operator in Java?

a)

To check the type of an object

b)

To create an instance of a class

c)

To cast an object to a different type

d)

To compare two objects

14.

Which of the following keywords allows a class to inherit from an interface?

a)

extends

b)

implements

c)

inherits

d)

uses

15.

How can you achieve polymorphism in Java?

a)

By method overloading only

b)

By method overriding only

c)

By both method overloading and overriding

d)

By using final classes

16.

What does the final keyword signify when used with a class?

a)

The class can be subclassed

b)

The class cannot be subclassed

c)

The class can only have one constructor

d)

The class is abstract

17.

Which of the following is a feature of Java’s garbage collection?

a)

Manual memory management

b)

Automatic memory management

c)

Explicit memory allocation

d)

None of the above

18.

In Java, what is the result of attempting to instantiate an abstract class?

a)

Compile-time error

b)

Run-time error

19.

Which method can be used to create a deep copy of an object?

a)

Cloneable interface

b)

Serialization

c)

Copy constructor

d)

All of the above

20.

When a class inherits from an interface, which of the following must be implemented?

a)

Only abstract methods

b)

Only non-abstract methods

c)

Both abstract and non-abstract methods

d)

Only static methods

21.

What happens if a method in a subclass has the same name and parameters as a method in its superclass?

a)

The superclass method is executed

b)

The subclass method is executed

c)

A compile-time error occurs

d)

The program fails to run

22.

Which of the following correctly describes a Java interface?

a)

It can have method implementations

b)

It can contain instance variables

c)

It can extend multiple classes

d)

It can only contain abstract methods

23.

In Java, a subclass can access the private members of its superclass by:

a)

Using public or protected getter and setter methods in the superclass

b)

Directly accessing them using the 'super' keyword

c)

Declaring the subclass in the same package

d)

Using the 'private' keyword in the subclass

24.

What is the purpose of the Serializable interface in Java?

a)

To create a deep copy of an object

b)

To allow objects to be serialized

c)

To enable thread safety

d)

To implement cloning

25.

How do you prevent a method from being overridden in a subclass?

a)

Declare it as final

b)

Declare it as private

26.

Which of the following statements about multiple inheritance of interfaces is true?

a)

It is allowed in Java

b)

It is not allowed in Java

c)

It leads to ambiguity

d)

Only one interface can be inherited

27.

Which of the following keywords is used to declare an inner class?

a)

inner

b)

static

c)

public

d)

class

28.

What is the purpose of the clone() method?

a)

To create a new instance of a class

b)

To create a shallow copy of an object

c)

To compare two objects

d)

To serialize an object

29.

What is the default visibility of a class member declared without any access modifier?

a)

Public

b)

Protected

c)

Private

d)

Package-private

30.

Which method in Java is called when an object is deserialized?

a)

finalize()

b)

readObject()

c)

deserialize()

d)

init()

31.

What is the result of attempting to cast an object to a class that it does not inherit from?

a)

Compile-time error

b)

Run-time exception

c)

It will return null

d)

It will create a new instance

32.

In the context of object serialization, what is a serialVersionUID?

a)

A unique identifier for each class

b)

A method used for serialization

33.

What is the purpose of a marker interface in Java?

a)

To provide methods for implementation

b)

To mark a class for specific behavior

c)

To prevent multiple inheritance

d)

To enforce type safety

34.

Which of the following statements about static members is true?

a)

Static members are associated with the instance of a class

b)

Static members can be accessed without creating an instance of a class

c)

Static members cannot be inherited

d)

Static members can only be private

35.

What happens if you do not override the toString() method in a class?

a)

The program will not compile

b)

The default implementation from Object class will be used

c)

It will throw a run-time exception

d)

It will return null

36.

What is an anonymous inner class in Java?

a)

A class defined without a name

b)

A class that does not inherit from any superclass

c)

A class that cannot access outer class members

d)

A class with multiple constructors

37.

Which of the following methods should be overridden for correct serialization of an object?

a)

finalize()

b)

readObject() and writeObject()

c)

clone()

d)

toString()

38.

When using super() in a constructor, what must be true?

a)

It must be the first statement in the constructor

b)

It must be called after any initialization

c)

It can only be called in the constructor of a subclass

d)

It cannot be used in abstract classes

39.

Which of the following is true about an inner class?

a)

It can be private, protected, or public

b)

It cannot have private members

c)

It can only be public

d)

It cannot be a static class

40.

Which of the following is a correct way to declare a static inner class?

a)

public class Outer { static class Inner {} }

b)

public class Outer { Inner static {} }

c)

static class Outer { class Inner {} }

d)

class Outer { static class Inner {} }

41.

Which of the following keywords can be used to prevent method overriding?

a)

final

b)

static

c)

abstract

d)

virtual

42.

Which of the following statements about the hashCode() method is true?

a)

It can return negative values

b)

It is mandatory to override hashCode() when equals() is overridden

c)

It is called automatically during object comparison

d)

It returns the memory address of the object

43.

How can you invoke a method of a superclass from a subclass?

a)

Using the base keyword

b)

Using the super keyword

c)

Directly, by method name

d)

Using the parent keyword

44.

In the context of OOP, what is encapsulation?

a)

Inheriting methods from a superclass

b)

Hiding the internal state and requiring all interaction to be performed through an object's methods

c)

Using multiple classes to implement a single function

d)

Overriding methods in subclasses

45.

What does the final keyword signify when used with a variable?

a)

The variable can be changed

b)

The variable can only be initialized once

c)

The variable can be accessed from anywhere

d)

The variable is a class constant

46.

Which of the following is the correct syntax for implementing an interface in Java?

a)

class MyClass implements MyInterface {}

b)

class MyClass inherits MyInterface {}

c)

class MyClass extends MyInterface {}

d)

MyClass : MyInterface {}

47.

In Java, what is method overloading?

a)

Having the same method name with different parameters in the same class

b)

Having the same method name with the same parameters in different classes

c)

Changing the method implementation in subclasses

d)

Using the same method name across different packages

48.

What happens if you attempt to serialize an object without implementing Serializable?

a)

The object will be serialized anyway

b)

A NotSerializableException is thrown

49.

If a class does not implement the Serializable interface, what will happen when you attempt to serialize an instance of that class?

a)

The object will be serialized without any issues

b)

A NotSerializableException will be thrown

c)

The object will be partially serialized

d)

The object will lose all its data

50.

What is the primary reason for using interfaces in Java?

a)

To implement multiple inheritance

b)

To provide a way to define abstract methods

c)

To allow different classes to communicate with each other

d)

To achieve abstraction and polymorphism

51.

Which of the following is NOT a feature of a constructor in Java?

a)

It must have the same name as the class

b)

It can be overloaded

c)

It has a return type

d)

It is called when an object is created

52.

Which keyword is used to access members of the superclass in Java?

a)

this

b)

base

c)

super

d)

parent

53.

What is the purpose of the instanceof operator?

a)

To check if an object is an instance of a specific class or subclass

b)

To cast an object to a specified class

c)

To compare two objects

d)

To clone an object

54.

Which of the following statements about abstract classes is true?

a)

The class cannot have constructors

b)

The class cannot be instantiated

c)

The class cannot have fields

d)

The class cannot implement interfaces

55.

Which of the following statements about final classes is true?

a)

They can be subclassed

b)

They can have constructors

c)

They cannot have any methods

d)

They cannot have any attributes

56.

In Java, what is the visibility of a member marked as protected?

a)

A) Accessible only within its own package

b)

B) Accessible only within its own class

c)

C) Accessible by subclasses and classes in the same package

d)

D) Accessible by any class

57.

Which of the following is true regarding the equals() method?

a)

It must be overridden if the == operator is used

b)

It checks for reference equality by default

c)

It can return null

d)

It must return a boolean value

58.

What is an interface?

a)

A class that cannot be instantiated

b)

A contract that classes can implement

c)

A special type of class with abstract methods

d)

A way to define constants

59.

Why is it important to override the hashCode() method when overriding equals()?

a)

To change the default hashing behavior

b)

To ensure consistent behavior with equals()

c)

To improve performance

d)

To enable object cloning

60.

Which of the following statements about inner classes is true?

a)

An inner class cannot access the outer class’s private members

b)

An inner class can be static

c)

An inner class can only be public

d)

An inner class can be instantiated without an outer class instance

61.

59. When you call the finalize() method on an object, which of the following occurs?

a)

The object's cleanup actions are performed before garbage collection.

b)

The object is immediately deleted from memory.

c)

The object's constructor is called again.

d)

The object becomes immutable.

62.

What happens when the finalize() method is called on an object in Java?

a)

The object is destroyed

b)

The object is marked for garbage collection

c)

The object's resources are released

d)

The object's state is saved

63.

What is the difference between == and equals() in Java?

a)

== compares references, while equals() compares values

b)

== compares values, while equals() compares references

c)

They are interchangeable

d)

== is used for primitives, while equals() is used for objects

64.

Which of the following can an abstract class do?

a)

Provide implementations for some methods

b)

Only have abstract methods

c)

Be instantiated directly

d)

Inherit from a concrete class

65.

Which of the following statements is true about interfaces in Java?

a)

An interface can extend multiple classes

b)

An interface can have method implementations

c)

An interface can contain fields

d)

An interface can extend multiple interfaces

66.

In the context of inheritance, what does the term “subclass” refer to?

a)

A class that inherits from another class

b)

A class that cannot be instantiated

c)

A class that contains inner classes

d)

A class that implements interfaces

67.

What does polymorphism allow in Java?

a)

Multiple classes to be instantiated from a single class

b)

Objects to be treated as instances of their parent class

c)

Methods to be defined only in abstract classes

d)

Variables to change type at runtime

68.

Which of the following is NOT a type of inner class?

a)

Member inner class

b)

Local inner class

c)

Anonymous inner class

d)

External inner class

69.

What keyword is used to define an interface in Java?

a)

interface

b)

abstract

70.

Which of the following statements about method overriding is true?

a)

The overriding method must have the same name and parameters as the method in the superclass

b)

The overriding method can have a different return type

c)

The overriding method can be more restrictive in terms of access

d)

All of the above

71.

Which of the following is true about the Object class in Java?

a)

It is the superclass of all classes

b)

It cannot be extended

c)

It contains only abstract methods

d)

It is not part of the Java API

72.

What is the purpose of the Serializable interface?

a)

To mark a class for serialization

b)

To prevent class modification

c)

To create constant values

d)

To implement security features

73.

What does the protected access modifier allow?

a)

Access only within the same package

b)

Access only within subclasses

c)

Access within the same package and subclasses

d)

Access from any class