wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

2-Term-MT-OOP

Total questions: 70

Worksheet time: 23mins

Name
Class
Date
1.
An entity that has a state, behavior, and identity with a well-defined role in problem space is called a/an:
a)
Class
b)
Object
c)
Attribute
d)
Method
2.
What is a class often referred to as in Object-Oriented Programming?
a)
Instance
b)
Field
c)
Blueprint
d)
Procedure
3.
Which keyword is used to create an object (an actual instance) of a class in Java?
a)
class
b)
instance
c)
create
d)
new
4.
The ability to ignore aspects of a subject not relevant to the current purpose to focus on those that are is defined as which OOP principle?
a)
Encapsulation
b)
Polymorphism
c)
Inheritance
d)
Abstraction
5.
What operator is used to access an object's fields and invoke its methods?
a)
Colon (:)
b)
Semicolon (;)
c)
Dot (.)
d)
Hash (#)
6.
The principle of hiding design or implementation information not relevant to the current object, often achieved by using private fields and public getters/setters, is called:
a)
Abstraction
b)
Polymorphism
c)
Inheritance
d)
Encapsulation
7.
What is the term for a data element of an object that stores information about it, also known as a data member or instance variable?
a)
Method
b)
Object
c)
Constructor
d)
Attribute
8.
What term describes the behavior of an object and is also called a function or a procedure?
a)
Field
b)
Attribute
c)
Method
d)
Package
9.
Inheritance is often referred to as what kind of relationship?
a)
"has-a" relationship
b)
"part-of" relationship
c)
"is-a" relationship
d)
"uses-a" relationship
10.
What is a method-like block of code used for creating and initializing a new object?
a)
Setter
b)
Method Overloader
c)
Constructor
d)
Abstract Method
11.
Which keyword is used to call the immediate superclass's constructor and must be the first statement in the subclass's constructor?
a)
this
b)
parent
c)
base
d)
super
12.
Which type of polymorphism is resolved during compilation and is also known as static polymorphism?
a)
Run Time Polymorphism
b)
Method Overriding
c)
Compile Time Polymorphism
d)
Dynamic Polymorphism
13.
A class that extends an abstract class must do which of the following, unless the subclass itself is declared abstract?
a)
Define a new constructor.
b)
Implement all abstract methods.
c)
Overload a method from the superclass.
d)
Use the super keyword.
14.
Which built-in Java package contains fundamental classes and is automatically imported into every Java program?
a)
java.util
b)
java.io
c)
java.net
d)
java.lang
15.
What concept means "many forms" and is the ability of an object to assume many different forms?
a)
Abstraction
b)
Encapsulation
c)
Polymorphism
d)
Inheritance
16.
The access modifier of an overriding method in a subclass must be:
a)
Less restrictive than the overridden method's access modifier.
b)
The same as the overridden method's access modifier.
c)
The same or less restrictive than the overridden method's access modifier.
d)
More restrictive than the overridden method's access modifier.
17.
What does the static keyword allow regarding class members?
a)
Restricts the member from being modified.
b)
Forces the class to be abstract.
c)
Allows access to members without instantiation.
d)
Declares the member as a constant.
18.
One primary use of the this keyword is to:
a)
Call the superclass's constructor.
b)
Disambiguate a local attribute from a local variable.
c)
Declare a variable as a constant.
d)
Define an abstract method.
19.
An Interface in Java is best described as a/an:
a)
Blueprint with implementation details.
b)
A class that cannot be instantiated.
c)
Contract in the form of a collection of method and constant declarations.
d)
A superclass that forces subclasses to implement certain methods.
20.
In OOP, polymorphism is primarily achieved through method overriding and:
a)
Attribute declaration
b)
Object instantiation
c)
Method overloading
d)
Constructor definition
21.

A Special Method

(a)  

22.

The programming approach whose core concept is to break down complex problems into smaller, manageable units.

(a)  

23.

The most restrictive access modifier in Java, which limits visibility only within the class where the member is declared.

(a)  

24.

The OOP principle that involves the grouping of data and the methods that operate on that data, while restricting direct access to some components.

(a)  

25.

The type of variables that an Interface in Java is explicitly prohibited from containing.

(a)  

26.

The default access level in Java (no keyword specified), which limits visibility to the class and the entire package.

(a)  

27.

The type of polymorphism that is resolved dynamically at runtime, typically associated with method overriding.

(a)  

28.

The access modifier that makes a class member visible to its own class, its package, and any subclass (even if the subclass is in a different package).

(a)  

29.

What the super keyword can be used to explicitly call when a subclass method has the exact same name and signature as an inherited superclass method.

(a)  

30.

What Java program structure element is a class that is defined entirely within the body of another class.

(a)  

31.

The keyword used when declaring a class to prevent any other class from inheriting it (subclassing).

(a)  

32.

The keyword used when declaring a method to prevent any subclass from altering its functionality (overriding).

(a)  

33.

The keyword that cannot be used in a constructor's declaration, along with static and abstract.

(a)  

34.

The type of data structure used to manage a collection of multiple objects of the same class.

(a)  

35.

The specific name for a type of polymorphism where multiple methods in the same class share the same name but have different parameter lists (signatures).

(a)  

36.

A construct used for grouping related classes and/or subpackages, which is analogous to a directory.

(a)  

37.

What class members are referred to as when they can be accessed directly using the class name, without first creating an instance of the class.

(a)  

38.

The keyword used in the class declaration syntax to establish an inheritance relationship with a parent class.

(a)  

39.

The programming concept that allows you to define a new complex data type (like a blueprint for objects).

(a)  

40.

The type of relationship in OOP (e.g., Aggregation and Composition) that signifies one object contains or references another object.

(a)  

41.

Given the class Lamp from the PPT snippet, which line correctly creates and initializes a new object named deskLamp?

a)
Lamp deskLamp
b)

new Lamp() = deskLamp

c)
Lamp deskLamp = new Lamp()
d)
deskLamp.Lamp = new Lamp
42.
What is the output of the following code snippet based on the Lamp class structure provided in the PPT? Lamp led = new Lamp(); led.isOn = false; led.turnOn();
a)
Light on? false
b)
Light on? true
c)
Compilation Error
d)
No output
43.
If you have a class Animal and a subclass Dog, which keyword must be used in the Dog class declaration to indicate inheritance?
a)
implements
b)
inherits
c)
extends
d)
uses
44.
In a subclass constructor, if you want to explicitly call the superclass's no-argument constructor, which statement must appear first?
a)
this()
b)
new super()
c)
super()
d)
parent()
45.
The code public class Test implements InterfaceA, InterfaceB { ... } demonstrates the ability of a Java class to:
a)
Implement multiple interfaces.
b)
Extend multiple classes.
c)
Use static polymorphism.
d)
Overload the constructor.
46.
Which of the following is the correct syntax for declaring a variable that can hold the value of an object from the Student class and is declared as final?
a)
final Student s = Student.new()
b)
const Student s = new Student()
c)
final Student s = new Student()
d)
Student final s = new Student
47.
Which keyword is used to refer to the current object inside an instance method or constructor, for example, to differentiate a parameter from an instance variable?
a)
current
b)
self
c)
super
d)
this
48.
Which Java keyword, when used with a class member (field or method), allows that member to be accessed without first creating an object of the class?
a)
final
b)
public
c)
abstract
d)
static
49.
An interface declaration should use which keyword?
a)
class
b)
abstract class
c)
contract
d)
interface
50.
If a method in a superclass is declared with public access, and a subclass overrides that method, which access modifier is NOT allowed for the overriding method in the subclass?
a)
public
b)
protected
c)
private
d)
default (package-private)
51.
Which method returns the number of Unicode values found in a string?
a)
length()
b)
codePointAt()
c)
offsetByCodePoints()
d)
codePointCount()
52.
What is the return type of the contains() method, which checks whether a string includes a sequence of characters?
a)
boolean
b)
int
c)
String
d)
char
53.
Which String method checks whether a string ends with the specified character(s)?
a)
startsWith()
b)
matches()
c)
endsWith()
d)
regionMatches()
54.
Which pair of methods compares two strings lexicographically, with one method ignoring case differences?
a)
equals() and equalsIgnoreCase()
b)
compareTo() and compareToIgnoreCase()
c)
indexOf() and lastIndexOf()
d)
length() and codePointCount()
55.
If you want to convert a string into an array of bytes, which method should you use?
a)
toCharArray()
b)
getChars()
c)
split()
d)
getBytes()
56.
What is the primary difference between the function of indexOf() and lastIndexOf()?
a)
indexOf() returns the position of the first found occurrence, while lastIndexOf() returns the position of the last found occurrence
b)
indexOf() can only find characters, while lastIndexOf() can find character sequences
c)
indexOf() returns a boolean, while lastIndexOf() returns an integer
d)
indexOf() searches using a regular expression, and lastIndexOf() searches using a literal string
57.
Which method is used to return a new character sequence that is a subsequence of the current sequence, and its return type is CharSequence?
a)
substring()
b)
concat()
c)
subSequence()
d)
charAt()
58.
The method trim() is used for what purpose?
a)
Converting a string to lower case letters
b)
Appending a string to the end of another string
c)
Returning the canonical representation for the string object
d)
Removing whitespace from both ends of a string
59.
Which method is used to split a string into an array of substrings?
a)
split()
b)
substring()
c)
getChars()
d)
join()
60.
What is the return type of the charAt() method?
a)
String
b)
char
c)
int
d)
boolean
61.

Imagine below is a complete java program

String s = "Java is a robust language. It is widely used for enterprise applications."; System.out.println(s.length());

The output is:

72

a)
TRUE
b)
FALSE
62.

Imagine below is a complete java program

String s = "The quick brown fox. The fox is running fast.";

System.out.println(s.indexOf("fox"));

The output is:

20

a)
TRUE
b)
FALSE
63.

Imagine below is a complete java program

String s = "This is line one. This is line two.";

System.out.println(s.contains("line one"));

The output is:

TRUE

a)
TRUE
b)
FALSE
64.

Imagine below is a complete java program

String s = "Method testing is critical. Make sure your inputs are valid.";

System.out.println(s.toUpperCase());

The output is:

METHOD TESTING IS CRITICAL. MAKE SURE YOUR INPUT ARE VALID.

a)
TRUE
b)
FALSE
65.

Imagine below is a complete Java program

String s = "Start here. End here.";

System.out.println(s.endsWith("here"));

The output is:

FALSE

a)
TRUE
b)
FALSE
66.

Imagine below is a complete java program

String s = "This sentence has three words. This sentence has four words.";

String replaced = s.replace("words", "terms");

System.out.println(replaced.indexOf("words"));

The output is:

-1

a)
TRUE
b)
FALSE
67.

Imagine below is a complete java program

String s = "\n\n Text with spaces. More spaces here. \n\n";

System.out.println(s.trim().length());

The output is:

42

a)
TRUE
b)
FALSE
68.

Imagine below is a complete java program

String s = "Alpha Beta Gamma. Delta Epsilon.";

System.out.println(s.substring(11, 16));

The output is:

. Del

a)
TRUE
b)
FALSE
69.

Imagine below is a complete java program

String s = "The index is 1. The index is 2.";

System.out.println(s.indexOf("index", 15));

The output is:

19

a)
TRUE
b)
FALSE
70.

Imagine below is a complete java program

String s = "Check. What is the length?";

System.out.println(s.charAt(1));

The output is:

h

a)
TRUE
b)
FALSE