WorksheetsObject Oriented Programming Midterm 2025
Total questions: 71
Worksheet time: 36mins
Name
Class
Date
1.
What is object-oriented programming?
a)
A programming paradigm focused on data rather than objects
b)
A programming paradigm based on the concept of "objects" containing data and methods
c)
A programming approach that only uses while loops
d)
A programming style that doesn't allow inheritance
2.
In Java, what keyword is used to create a new instance of a class?
a)
create
b)
instance
c)
new
d)
object
3.
Which of the following is a key component of a Java source code file?
a)
The database connector
b)
The class header
c)
The Python interpreter
d)
The HTML markup
4.
What is inheritance in object-oriented programming?
a)
The ability of a class to implement multiple interfaces
b)
The process of hiding implementation details
c)
A mechanism where a new class is derived from an existing class
d)
A way to restrict access to class members
5.
What is the purpose of a constructor in Java?
a)
To destroy objects when they are no longer needed
b)
To initialize objects when they are created
c)
To connect to external databases
d)
To compile the code into bytecode
6.
Which of the following is a benefit of using methods with parameters?
a)
They allow the method to be called without arguments
b)
They make the code run faster
c)
They provide specific values for the method to use
d)
They prevent inheritance from working properly
7.
What does a method with a void return type do?
a)
It returns a Boolean value
b)
It returns multiple values
c)
It doesn't return any value
d)
It always returns zero
8.
What is the purpose of comments in Java code?
a)
To make the program run faster
b)
To automatically debug the code
c)
To annotate code and explain functionality
d)
To create variables
9.
What is a potential concern when using AI-generated code?
a)
It always produces code that is too complex
b)
It may contain inherent bias
c)
It only works with Python, not Java
d)
It requires a paid subscription
10.
What is a selection statement in Java?
a)
A statement that selects which class to inherit from
b)
A statement that chooses a method to override
c)
A statement that executes different code based on whether a condition is true or false
d)
A statement that selects which variables to initialize
11.
What is the NOT logical operator in Java?
a)
&
b)
^
c)
!
d)
~
12.
Which of the following is NOT mentioned as a component of the problem-solving process for debugging?
a)
Identifying errors in a program
b)
Developing potential solutions
c)
Testing solutions
d)
Purchasing debugging software
13.
What does the turnLeft() method in the Painter class do?
a)
Moves the Painter object to the left
b)
Rotates the Painter object 90 degrees counterclockwise
c)
Paints the left side of a square
d)
Returns a Boolean indicating if the left side is clear
14.
In object-oriented programming, what is the relationship between a class and an object?
a)
A class is a specific instance of an object
b)
An object is a blueprint for a class
c)
A class is a blueprint for objects
d)
Objects and classes are the same thing
15.
What is the primary purpose of conducting a code review?
a)
To ensure the code runs without errors
b)
To receive a grade on the assignment
c)
To receive feedback from peers on code quality and style
d)
To check for plagiarism
16.
What is the purpose of the Backpack feature in Java Lab?
a)
To store personal items while coding
b)
To save classes for use in future projects
c)
To back up code to the cloud
d)
To share code with other students
17.
What is the main method in a Java program?
a)
A method that calculates the average of values
b)
The entry point of a Java application where execution begins
c)
A method that must be overridden in subclasses
d)
A method that connects to external databases
18.
In the context of the Painter class, what does the paint() method require?
a)
A numeric parameter
b)
A Boolean parameter
c)
A string literal parameter specifying the color
d)
No parameters
19.
What is a syntax error in Java?
a)
An error that occurs during program execution
b)
An error in the program logic
c)
A violation of the language's grammar rules
d)
An error caused by user input
20.
What is the purpose of the move() method in the Painter class?
a)
To move the Painter object one unit in the direction it is facing
b)
To teleport the Painter to a specific coordinate
c)
To create a new Painter object
d)
To move the Painter diagonally
21.
What happens when you create a subclass in Java?
a)
The subclass loses all methods from its superclass
b)
The subclass can only have methods with the same names as the superclass
c)
The subclass inherits attributes and behaviors from its superclass
d)
The superclass gains all methods from the subclass
22.
What is the relationship between the PainterPlus class and the Painter class?
a)
They are completely unrelated classes
b)
PainterPlus is a superclass of Painter
c)
PainterPlus is a subclass of Painter
d)
They are interface implementations
23.
What is a string literal in Java?
a)
A sequence of characters enclosed in double quotes
b)
A variable that can only store one character
c)
A method that returns text
d)
A class that handles text processing
24.
What is the purpose of iteration in programming?
a)
To create new objects
b)
To repeat a block of code multiple times
c)
To inherit from multiple classes
d)
To connect to databases
25.
What is good programming style?
a)
Using as few comments as possible
b)
Writing all code on a single line
c)
Following formatting guidelines and best practices
d)
Using only while loops instead of if statements
26.
What is the main challenge associated with AI-generated code?
a)
It is always too slow
b)
It may contain errors or not fully understand the context
c)
It is too expensive to generate
d)
It only works with certain programming languages
27.
What does the canMove() method in the Painter class do?
a)
It moves the Painter in all four directions
b)
It checks if the Painter can move forward in the direction it is facing
c)
It enables movement for a disabled Painter
d)
It calculates the maximum distance the Painter can move
28.
What is a multi-line comment in Java?
a)
A comment that spans multiple lines and begins with /* and ends with */
b)
A series of single-line comments on consecutive lines
c)
A comment that automatically wraps to the next line
d)
A comment that is visible to multiple programmers simultaneously
29.
What is the purpose of debugging in programming?
a)
To add new features to a program
b)
To identify and fix errors in a program
c)
To create documentation
d)
To optimize code for speed
30.
In programming, what is a bug?
a)
A virus that infects the computer
b)
An error or flaw in a program that causes it to behave unexpectedly
c)
A feature that hasn't been implemented yet
d)
A piece of hardware that's malfunctioning
31.
What is the difference between a one-way and a two-way selection statement?
a)
A one-way selection has one condition, while a two-way has two conditions
b)
A one-way selection only has an if block, while a two-way has both if and else blocks
c)
A one-way selection works with one data type, while a two-way works with two data types
d)
There is no difference; they are different names for the same thing
32.
What does it mean to "instantiate" an object in Java?
a)
To delete an object from memory
b)
To create an instance of a class using the new keyword
c)
To inherit from a superclass
d)
To override a method
33.
What is the primary purpose of a constructor in Java?
a)
To destroy objects when they are no longer needed
b)
To initialize instance variables when an object is created
c)
To define the methods that an object can perform
d)
To establish inheritance relationships between classes
34.
Which keyword is used to access the instance variables of the current object?
a)
super
b)
new
c)
this
d)
static
35.
What is encapsulation in object-oriented programming?
a)
The process of creating multiple instances of a class
b)
The hiding of implementation details and restricting direct access to data
c)
The ability of a class to inherit from multiple parent classes
d)
The process of compiling a program into bytecode
36.
Which of the following correctly declares a private instance variable in Java?
a)
instance String name;
b)
public String name;
c)
private String name;
d)
protected String name;
37.
What is the difference between a no-argument constructor and a parameterized constructor?
a)
A no-argument constructor cannot be overridden, while a parameterized constructor can
b)
A no-argument constructor sets default values, while a parameterized constructor sets specific values
c)
A no-argument constructor is automatically created by Java, while a parameterized constructor must be explicitly defined
d)
A no-argument constructor is used for primitive data types, while a parameterized constructor is used for objects
38.
Which Java class is used to collect input from users?
a)
UserInput
b)
Console
c)
Input
d)
Scanner
39.
What does the super keyword do in a subclass constructor?
a)
It prevents the subclass from inheriting attributes from the superclass
b)
It calls the constructor of the superclass
c)
It makes the subclass methods override the superclass methods
d)
It creates a new instance of the superclass
40.
Which of the following is NOT a primitive data type in Java?
a)
boolean
b)
String
c)
double
d)
int
41.
What is the purpose of an accessor method (getter) in a class?
a)
To change the values of instance variables
b)
To create new instances of a class
c)
To retrieve the values of instance variables
d)
To establish inheritance between classes
42.
What happens when you divide an integer by zero in Java?
a)
The result is infinity
b)
The result is zero
c)
An ArithmeticException is thrown
d)
The program continues with a default value
43.
What is the purpose of the toString() method in Java?
a)
To convert numeric values to strings
b)
To provide a string representation of an object
c)
To check if two objects are equal
d)
To convert strings to primitive types
44.
Which operator is used to calculate the remainder after division in Java?
a)
%
b)
/
c)
^
d)
#
45.
What is a mutator method (setter) used for in a class?
a)
To retrieve the values of instance variables
b)
To change the values of instance variables
c)
To delete instance variables
d)
To create new instance variables
46.
In Java, what is the Object class?
a)
A class that can only contain objects, not primitive types
b)
The superclass of all other classes
c)
A class that defines the basic structure of all objects
d)
A class that can only be instantiated once
47.
What is inheritance in object-oriented programming?
a)
The ability to create multiple instances of a class
b)
The process of hiding implementation details
c)
The mechanism by which one class acquires the properties of another class
d)
The process of compiling a program
48.
Which of the following is true about compound assignment operators?
a)
They cannot be used with primitive data types
b)
They perform an operation and assignment in a single step
c)
They are used to compare two values
d)
They can only be used in constructors
49.
What is a UML diagram used for in programming?
a)
To compile code more efficiently
b)
To visually represent the structure and relationships of classes
c)
To debug errors in code
d)
To convert code between different programming languages
50.
Which of the following is NOT a valid way to use the this keyword?
a)
To refer to the current object's instance variables
b)
To call another constructor in the same class
c)
To create a new instance of the current class
d)
To disambiguate instance variables from parameters with the same name
51.
What is the scope of a local variable in Java?
a)
The entire class in which it is declared
b)
The entire program
c)
The block or method in which it is declared
d)
Any class that inherits from the class in which it is declared
52.
Which of the following is a benefit of using accessor and mutator methods instead of directly accessing instance variables?
a)
It makes the code run faster
b)
It reduces the amount of code needed
c)
It allows for validation of data before changing instance variables
d)
It eliminates the need for constructors
53.
What is the main purpose of a class in object-oriented programming?
a)
To execute the main method of a program
b)
To serve as a blueprint for creating objects
c)
To organize methods in alphabetical order
d)
To connect the program to external databases
54.
When would you use a parameterized constructor instead of a no-argument constructor?
a)
When you want to create multiple instances of the same class
b)
When you need to initialize instance variables with specific values
c)
When your class contains only static methods
d)
When your program needs to run faster
55.
What does the private access modifier do when applied to an instance variable?
a)
Makes the variable accessible only within the class where it is declared
b)
Makes the variable accessible to any class in the same package
c)
Makes the variable accessible to subclasses only
d)
Makes the variable accessible to all classes in the program
56.
In the context of inheritance, what does a subclass inherit from its superclass?
a)
Only private instance variables
b)
Only public methods
c)
Both attributes and behaviors (non-private instance variables and methods)
d)
Nothing is inherited automatically
57.
What is the purpose of the Java Scanner class?
a)
To scan for errors in your code
b)
To read input from various sources such as keyboard or files
c)
To scan class files for potential security vulnerabilities
d)
To convert primitive types to objects
58.
What happens when a subclass constructor does not explicitly call the superclass constructor?
a)
The program will not compile
b)
The superclass's no-argument constructor is called automatically
c)
The subclass will not inherit any properties from the superclass
d)
An exception is thrown at runtime
59.
What is the difference between primitive and reference data types in Java?
a)
Primitive types start with lowercase letters, reference types start with uppercase
b)
Primitive types store actual values, reference types store addresses to objects
c)
Primitive types can only be used in methods, reference types can be used anywhere
d)
Primitive types are faster, reference types are more accurate
60.
What is the primary purpose of the this() constructor call in Java?
a)
To access instance variables of the current object
b)
To call a constructor in the superclass
c)
To call another constructor in the same class
d)
To create a new instance of the current class
61.
Which of the following is a good practice when designing classes?
a)
Making all instance variables public for easy access
b)
Avoiding the use of constructors whenever possible
c)
Providing accessor and mutator methods for private instance variables
d)
Creating as many instance variables as possible
62.
What happens when you try to print an object reference without overriding the toString() method?
a)
The program will not compile
b)
A string containing the class name and memory address is printed
c)
All instance variable values are automatically printed
d)
Nothing is printed
63.
What is the purpose of the compound assignment operator +=?
a)
It adds two values and assigns the result to a new variable
b)
It adds a value to a variable and assigns the result back to the variable
c)
It checks if two values are equal and returns a boolean
d)
It concatenates two strings
64.
Which of the following statements about the super keyword is FALSE?
a)
It can be used to call a method in the superclass
b)
It can be used to access instance variables of the superclass
c)
It can be used outside of a class that extends another class
d)
It must be the first statement in a constructor if used to call the superclass constructor
65.
What is the result of the expression 17 % 5 in Java?
a)
3.4
b)
3
c)
2
d)
5.67
66.
What is a good reason to make an instance variable private?
a)
To make the program run faster
b)
To save memory
c)
To control access and ensure data integrity
d)
To make the variable accessible to all classes
67.
What is the default value of an instance variable of type boolean in Java if not explicitly initialized?
a)
true
b)
false
c)
null
d)
0
68.
Which of the following is NOT a component typically found in a UML class diagram?
a)
Class name
b)
Attributes
c)
Methods
d)
Comments from code review
69.
What is method overriding in Java?
a)
Defining a method in a subclass with the same name and parameters as in the superclass
b)
Defining multiple methods with the same name but different parameters in the same class
c)
Hiding a method so it cannot be called
d)
Creating a method that can take a variable number of arguments
70.
What is the difference between = and == in Java?
a)
= is used for assignment, == is used for comparison
b)
= is used for primitive types, == is used for objects
c)
= is used in declarations, == is used in methods
d)
They are interchangeable
71.
What does it mean to instantiate an object?
a)
To declare a new class
b)
To create an instance of a class using the new keyword
c)
To inherit from a superclass
d)
To delete an object when it's no longer needed
100 %
