Complete Rationales | OOP Principles | Stacks Queues BST |
Sorting Searching | Inheritance Polymorphism | Java
Programming
Here is a comprehensive 150-question practice exam for CSE 205 (Object-
Oriented Programming and Data Structures). Questions cover all major topics
including OOP principles (inheritance, polymorphism, encapsulation), data
structures (stacks, queues, linked lists, trees, ArrayLists), algorithms (sorting,
searching, recursion), exception handling, and software development processes.
Each question includes the correct answer and a detailed rationale based on
standard Java programming concepts.
Section 1: Object-Oriented Programming Principles (Questions 1-30)
1. The relationship between a class and an object is best described as:
A) objects are instances of classes
B) classes are instances of objects
C) classes are programs while objects are variables
D) objects and classes are the same thing
E) objects are the instance data of classes
Answer: A – objects are instances of classes
Rationale: 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 .
2. To define a class that will represent a car, which of the following definitions is
most appropriate?
, A) public class CAR
B) public class car
C) private class car
D) private class Car
E) public class Car
Answer: E – public class Car
Rationale: Java naming conventions dictate that class names should begin
with an uppercase letter and use CamelCase. Classes should typically be
declared public to allow access from other files. The name should be meaningful
and descriptive .
3. Which of the following reserved words in Java is used to create an instance of
a class?
A) new
B) public
C) public or private, either could be used
D) class
E) import
Answer: A – new
Rationale: The new keyword is used to allocate memory and create a new
object (instance) of a class. For example: Car myCar = new Car(); .
4. What does acronym API stand for?
A) Application Parameter Internet
B) Application Programming Interface
C) Apply Programming Interactive
D) Abstraction Programming Interface
,Answer: B – Application Programming Interface
Rationale: An API is a set of rules, protocols, and tools for building software
applications. In Java, the Java API is a collection of pre-written classes, packages,
and interfaces that provide ready-to-use functionality .
5. A class' constructor usually defines:
A) how an object is initialized
B) how an object is interfaced
C) if the instance data are accessible outside of the object directly
D) the number of methods in the class
Answer: A – how an object is initialized
Rationale: A constructor is a special method that has the same name as the
class and no return type. It is automatically called when an object is created and is
used to initialize the object's instance variables to appropriate initial values .
6. Which of the following is true regarding subclasses?
A) A subclass has access to private instance variables of its superclass.
B) A subclass does not have access to public instance variables of its
superclass.
C) A subclass must specify the implicit parameter to use methods inherited
from its superclass.
D) A subclass has NO access to private instance variables of its superclass.
Answer: D – A subclass has NO access to private instance variables of its
superclass
Rationale: private members of a superclass are not accessible directly in a
subclass. Subclasses can only directly access public and protected members. To
access private members, subclasses must use public or protected getter/setter
methods provided by the superclass .
, 7. A class that represents a more specific entity in an inheritance hierarchy is
called a/an:
A) Default Class
B) Superclass
C) Subclass
D) Inheritance class
Answer: C – Subclass
Rationale: In inheritance, the subclass (also called derived class or child class)
extends the superclass and represents a more specialized version. For example,
if Vehicle is a superclass, Car would be a subclass representing a more specific
entity .
8. You are creating a class inheritance hierarchy about motor vehicles that will
contain classes named Vehicle, Auto, and Motorcycle. Which of the following
statements is correct?
A) Vehicle should be the default class, while Auto and Motorcycle should be
the subclasses.
B) Vehicle should be the superclass, while Auto and Motorcycle should be
the subclasses.
C) Vehicle should be the subclass, while Auto and Motorcycle should be the
superclasses.
D) Vehicle should be the subclass, while Auto and Motorcycle should be the
default classes.
Answer: B – Vehicle should be the superclass, while Auto and Motorcycle should
be the subclasses
Rationale: In an inheritance hierarchy, the more general class (Vehicle) is the
superclass, and more specific classes (Auto, Motorcycle) are subclasses that
inherit from the superclass. This follows the "is-a" relationship: an Auto is a
Vehicle .