FREE AP CSA Object-Oriented Programming Questions and Answers

0%

What is the correct way to create an object from the following class?

Correct! Wrong!

The constructor of the Car class requires a String parameter (color). A: Fails because there is no default constructor (Car() without arguments). C: Fails because new is required to instantiate objects in Java. D: Incorrect syntax.

How does encapsulation improve code quality?

Please select 2 correct answers

Correct! Wrong!

Encapsulation ensures that: Implementation details are hidden (achieved using private variables). Controlled access to class variables is provided through getters and setters. Making variables public (A) breaks encapsulation, and making methods static (D) is unrelated to encapsulation.

What is the output of the following code?

Correct! Wrong!

myDog is declared as Animal but instantiated as Dog. The overridden method makeSound() in the Dog class is called due to polymorphism.

Which of the following statements are true about method overloading and overriding?

Please select 3 correct answers

Correct! Wrong!

A: Overloading happens within the same class but with different parameter lists. B: Overriding occurs when a subclass modifies a method from its parent class. D: Overridden methods must have the same name, parameters, and return type. C is incorrect because overloaded methods must have the same method name.

What is true about abstract classes in Java?

Please select 3 correct answers

Correct! Wrong!

A: Abstract classes can have a mix of abstract and concrete methods. B: Abstract classes cannot be instantiated directly. D: A subclass must implement all abstract methods or be declared abstract itself. C is incorrect because an abstract class can have zero abstract methods.

Premium Tests $49/mo
FREE February-2025