ASU CSE 205 OBJECT-ORIENTED
PROGRAMMING AND DATA STRUCTURES
FINAL EXAMINATION: STUDY GUIDE |
LATEST UPDATE 2026/2027 | PRACTICE
QUESTIONS AND ANSWERS | EXAM REVIEW
TABLE OF CONTENTS
I. Java Fundamentals, Variables, and Operators
II. Object-Oriented Programming Principles
III. Classes, Objects, and Encapsulation
IV. Inheritance and Polymorphism
V. Exception Handling
VI. Stacks and Queues
VII. Linked Lists
VIII. Binary Search Trees
IX. Recursion
X. Sorting and Searching Algorithms
XI. Algorithm Complexity Analysis
XII. Java Collections Framework
, Page 2 of 66
question 1: What is the output of the following Java code? int x = 5; int y = x++;
System.out.println(x + " " + y);
Correct Answer: 6 5
The post-increment operator x++ returns the current value of x (5) to assign to y, then
increments x to 6. Pre-increment ++x would increment first then assign (6 6). This is a
common exam question testing understanding of increment operators.
question 2: Which of the following is a valid declaration of a constant in Java?
Correct Answer: final double PI = 3.14159;
The final keyword in Java is used to declare constants. Unlike C++, Java does not have a
const keyword. Once a final variable is assigned, its value cannot be changed. Constants are
typically declared as static final for class-level constants.
question 3: What will be the output of System.out.println(5 + 5 + "5");?
Correct Answer: 105
Java evaluates expressions from left to right. First, 5 + 5 evaluates to the integer 10. Then,
10 + "5" performs string concatenation, converting 10 to "10" and concatenating with "5" to
produce "105". Understanding operator precedence and associativity is crucial for predicting
output.
question 4: What is the result of 10 % 3 in Java?
Correct Answer: 1
The modulus operator % returns the remainder after division. 10 divided by 3 is 3 with a
remainder of 1. The modulus operator is commonly used to check for even/odd numbers,
wrap around arrays, and implement circular data structures.
question 5: What happens if a variable is declared but not initialized inside a method?
Correct Answer: Compilation error
Local variables in Java must be initialized before use. Unlike instance variables, which
receive default values, local variables do not have default values and the compiler will issue
an error if they are used without initialization. This is a safety feature to prevent undefined
behavior.
, Page 3 of 66
question 6: What is the default value of an int instance variable in Java?
Correct Answer: 0
Instance variables (and static variables) are initialized to default values by the Java runtime.
The default for int is 0, for double is 0.0, for boolean is false, and for reference types it is
null. Local variables do not receive default values and must be explicitly initialized.
question 7: Which keyword is used in Java to create an instance of a class?
Correct Answer: new
The new keyword allocates memory for an object and invokes the class constructor. For
example, Car myCar = new Car(); creates a new Car object. The new keyword is fundamental
to object instantiation in Java and returns a reference to the newly created object.
question 8: What is the purpose of the this keyword in Java?
Correct Answer: Refers to the current object instance
The this keyword is used to differentiate instance variables from parameters (this.x = x), call
another constructor (this(args) must be the first statement), and return the current instance
for method chaining. It cannot be used in a static context because there is no current
instance.
question 9: Which access modifier makes a member accessible only within the same class?
Correct Answer: private
The private access modifier is the most restrictive, allowing access only within the same
class. It is used for encapsulation and data hiding, ensuring that internal implementation
details are not exposed. Getters and setters provide controlled access to private data.
question 10: What is the relationship between a class and an object?
Correct Answer: Objects are instances of classes.
A class is a blueprint or template that defines the structure and behavior of objects. An object
is a specific instance of a class created in memory using the new keyword. You can create
multiple objects from a single class, each with its own state.
question 11: Which of the following statements about comparing objects in Java is correct?
, Page 4 of 66
Correct Answer: The equals method is used to compare whether two objects have the
same contents.
The == operator compares references (whether two variables point to the same object), while
the equals method (when properly overridden) compares the contents of objects. The default
equals method in Object class behaves like ==, so classes should override equals to provide
meaningful comparison.
question 12: What does the toString() method return if not overridden in a class?
Correct Answer: The name of the class followed by a hash code.
The default toString() method in the Object class returns a string consisting of the class
name, the @ character, and the unsigned hexadecimal representation of the object's hash
code. Classes should override toString() to provide a meaningful string representation.
question 13: What is encapsulation in object-oriented programming?
Correct Answer: Bundling data and methods within a class and controlling access to
that data.
Encapsulation assigns responsibilities to objects and hides internal implementation details. It
is achieved through access modifiers (private, protected, public) and provides a clear
interface for interacting with objects while protecting their internal state.
question 14: What is the benefit of data hiding?
Correct Answer: We can make an object truly responsible for what it knows and what it
does.
Data hiding ensures that an object's internal state can only be modified through its own
methods, maintaining consistency and preventing invalid states. This makes code more
maintainable, testable, and less prone to errors caused by external interference.
question 15: What is the purpose of a getter method?
Correct Answer: To provide read access to a private instance variable.
Getter methods (accessors) return the value of a private field. They allow controlled access to
data without exposing the field directly. Implementing a getter without a corresponding setter
creates a read-only property, which is useful for constants or calculated values.