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.
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.
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.
Answer is 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.
C is correct.