Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 35

Given the definition of the Vehicle class:

class Vehicle {

String name;

void setName (String name) {

this.name = name;

}

String getName() {

return name;

}

}

Which action encapsulates the Vehicle class?

    Correct Answer: D

    Encapsulation in object-oriented programming is the concept of restricting direct access to some of an object's components and can be achieved by making the data variables private. This ensures that the data can only be accessed through public methods (like getName and setName) that maintain control over how the data is set or retrieved. Hence, making the name variable private is the action that encapsulates the Vehicle class.

Discussion
aymanjOption: D

D is Correct

asdfjhfgjuaDCVOption: D

D is the correct answer

steefaandOption: D

D is correct and members should be private.

r1muka5Option: D

Correct answer is D.

WilsonKKerllOption: D

Answer is D.