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

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?

Vehicle class public.

    Correct Answer: C

    Encapsulation in object-oriented programming is achieved by making the data members private and providing public getter and setter methods to access and modify them. This ensures that the internal representation of an object is hidden from the outside. Therefore, making the 'name' variable private would encapsulate the Vehicle class.

Discussion
DestroyerOption: C

Answer is C

iSnoverOption: C

For encapsulation to be carried out, the variable must be private and accessed via methods, starting with "get" or "is" also for "boolean" and "set". So the answer is C.

steefaandOption: C

C is correct.