What is the main difference in memory storage between primitives and objects?
A. Primitives store references, objects store direct values
B. Primitives store values directly, objects store references to data
C. Both store references, but objects store more data
D. Both store values directly
B. Primitives store values directly, objects store references to data
An IS-A relationship represents:
A. A component relationship
B. A subclass-superclass relationship
C. Two unrelated classes
D. A variable stored inside another class
B. A subclass-superclass relationship
Polymorphism allows:
A. Multiple constructors in one class
B. One variable type to refer to many subclass objects
C. A class to inherit from multiple parents
D. Private variables to be public
B. One variable type to refer to many subclass objects
If a class does not use extends, it automatically extends:
A. Main
B. String
C. Object
D. System
C. Object
A HAS-A relationship describes:
A. Inheritance
B. Polymorphism
C. A whole-part relationship
D. Dynamic binding
C. A whole-part relationship
When a primitive is passed into a method:
A. The original variable is permanently changed
B. The method receives the original memory address
C. A copy of the value is passed
D. The variable becomes null inside the method
C. A copy of the value is passed
If Student extends Person, this means:
A. Student HAS-A Person
B. Person inherits Student’s methods
C. Student IS-A Person
D. Student replaces Person
C. Student IS-A Person
Dynamic binding means Java decides which method to execute:
A. At compile time based on variable type
B. Before the program starts
C. At runtime based on object type
D. When the class is written
C. At runtime based on object type
The default toString() method returns:
A. A readable summary of fields
B. Only the object’s variable names
C. The class name and memory address
D. The object’s constructor
C. The class name and memory address
If a Car has an Engine as an instance variable, this is:
A. Inheritance
B. Composition
C. Overriding
D. Polymorphism
B. Composition
When an object is passed into a method:
A. The entire object is duplicated in memory
B. The reference is copied, pointing to the same object
C. Only primitive fields are copied
D. A new object is automatically created
B. The reference is copied, pointing to the same object
Which members are inherited by a subclass?
A. Only private variables
B. All constructors automatically
C. Public instance methods
D. Static variables only
C. Public instance methods
If Shape s = new Circle(); and you call s.getArea(), Java uses:
A. Shape’s version always
B. Circle’s version at runtime
C. Both versions simultaneously
D. The version defined in main
B. Circle’s version at runtime
The default equals() method checks:
A. If two objects have equal data
B. If two references point to the same location
C. If two objects have the same class
D. If their toString() values match
B. If two references point to the same location
Composition is often preferred because:
A. It prevents method overriding
B. It eliminates constructors
C. It increases flexibility and reduces deep inheritance
D. It makes classes global
C. It increases flexibility and reduces deep inheritance
A NullPointerException occurs when:
A. An object runs out of memory
B. A reference variable points to multiple objects
C. A method is called on a variable that is null
D. Two objects share the same reference
C. A method is called on a variable that is null
Although constructors are not inherited, a subclass must:
A. Rewrite all superclass methods
B. Call the superclass constructor
C. Override every method
D. Duplicate private variables
B. Call the superclass constructor
Why can a method parameter declared as Shape accept a Circle object?
A. Because Circle overrides all methods
B. Because Circle IS-A Shape
C. Because Shape HAS-A Circle
D. Because Circle is abstract
B. Because Circle IS-A Shape
When we override equals(), we usually want to compare:
A. Memory addresses
B. Constructor types
C. Logical data inside objects
D. Object sizes
C. Logical data inside objects
In Java, composition is implemented by:
A. Using extends
B. Declaring an object as an instance variable
C. Overriding Object methods
D. Using static variables
B. Declaring an object as an instance variable
Which statement best explains why modifying an object inside a method affects the caller?
A. Java passes objects by value
B. Java copies the entire object automatically
C. Both variables refer to the same memory location
D. Objects are global by default
C. Both variables refer to the same memory location
All classes in Java automatically inherit from:
A. String
B. Main
C. Object
D. Class
C. Object
An array declared as Shape[] can store:
A. Only Shape objects
B. Only one subclass type
C. Any object unrelated to Shape
D. Shape objects and any subclass of Shape
D. Shape objects and any subclass of Shape
Overriding a method means:
A. Deleting the superclass version
B. Creating a new method with a different name
C. Redefining an inherited method with the same signature
D. Making the method private
C. Redefining an inherited method with the same signature
Which scenario best represents composition?
A. A Circle extends Shape
B. A Teacher extends Person
C. A Laptop contains a Battery object
D. A Dog overrides speak()
C. A Laptop contains a Battery object