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?
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?
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.
D is Correct
D is the correct answer
D is correct and members should be private.
Correct answer is D.
Answer is D.