answersLogoWhite

0

What is an accessor?

Updated: 10/23/2022
User Avatar

Wiki User

15y ago

Best Answer

An accessor is a method in a Java Bean that is used to access the private variables of the class.

Usually instance variables in a bean are declared as private and they can be accessed only via these accessor methods.

Ex:

public class Employee {

private String name = "";

private int age = 0;

public String getName(){

return this.name;

}

public void setName(String nm){

this.name = nm;

}

public int getAge(){

return this.age;

}

public void setAge(int ag){

this.age = ag;

}

}

In the above example name and age are instance variables and the methods beginning with get and set are the accessor methods.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is an accessor?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Are accessor member functions a sign of poor class design?

No, accessor member functions are a sign of good class design, particularly in terms of data encapsulation.


What is the difference between mutuator and accessor methods?

Mutator: Put something into the class (change something). By convention, has a name that starts with "set", for example, "getName". Accessor: Get something out of the class (find out the class's state). By convention, has a name that starts with "get", for example, "getName". For logical values, "is" is used instead, for example, "isActive".


What method gets a value from a class s field but does not change it?

An accessor method can be used to get a value from a class without changing the value.


Examples of accessor method?

Accessors are methods defined inside classes to access the private variables of the class. It is always a good practice to have instance variables as private so that, other classes cannot access them directly. This would avoid unwanted modification of data. These variables can be accessed only via their respective accessor methods. Ex: public class Test { private String name = ""; public String getName(){ return this.name; } Public void setName(String val){ this.name = val; } } Here getName and setName are the accessor methods for the variable name.


Define the java terms of accessor?

Accessors are methods defined inside classes to access the private variables of the class. It is always a good practice to have instance variables as private so that, other classes cannot access them directly. This would avoid unwanted modification of data. These variables can be accessed only via their respective accessor methods. Ex: public class Test { private String name = ""; public String getName(){ return this.name; } Public void setName(String val){ this.name = val; } } Here getName and setName are the accessor methods for the variable name.

Related questions

Are accessor member functions a sign of poor class design?

No, accessor member functions are a sign of good class design, particularly in terms of data encapsulation.


Who is the person who assigns to property for tax purpose?

tax accessor


What is the difference between mutuator and accessor methods?

Mutator: Put something into the class (change something). By convention, has a name that starts with "set", for example, "getName". Accessor: Get something out of the class (find out the class's state). By convention, has a name that starts with "get", for example, "getName". For logical values, "is" is used instead, for example, "isActive".


What method gets a value from a class s field but does not change it?

An accessor method can be used to get a value from a class without changing the value.


Examples of accessor method?

Accessors are methods defined inside classes to access the private variables of the class. It is always a good practice to have instance variables as private so that, other classes cannot access them directly. This would avoid unwanted modification of data. These variables can be accessed only via their respective accessor methods. Ex: public class Test { private String name = ""; public String getName(){ return this.name; } Public void setName(String val){ this.name = val; } } Here getName and setName are the accessor methods for the variable name.


Define the java terms of accessor?

Accessors are methods defined inside classes to access the private variables of the class. It is always a good practice to have instance variables as private so that, other classes cannot access them directly. This would avoid unwanted modification of data. These variables can be accessed only via their respective accessor methods. Ex: public class Test { private String name = ""; public String getName(){ return this.name; } Public void setName(String val){ this.name = val; } } Here getName and setName are the accessor methods for the variable name.


Why can't the accessor member function change any of the values in a class in C plus plus?

Nothing stops a member function from changing any of the values in a class. By convention, an accessor function is used to give read only access to class data, but that does not mean that it is prohibited from doing so. It is a member function, after all, and it has all the rights of any member function of the class.


How should we then live dvd?

This is a standard survey answer (4/16), submitted to test the accuracy of the accessor, please select the 'yes' option and continue.- The Swag Survey Team


How can you access private functions of a class from the Main function in Cpp?

Any member functions and data members declared as 'private' in a class, can only be accessed directly by functions within the class.They cannot be accessed directly by derived objects, nor from anywhere outside an object of the class, such as from the Main function.To access private class members, you must rely on what are called accessor functions. Accessor functions are functions inside the class, either public or protected, which automatically have access to private members.If a function from Main, or elsewhere outside the class hierarchy, needs access, then you need to use publicaccessor functions. For derived class access, you can use protected accessor functions.


What is a constant in qbasic?

A constant in any language is an instance of a data type for which the assigned value cannot be altered by the program. In the case of complex objects (particularly in object-oriented languages), the term constant applies to the logical representation of the object as viewed by the client, rather than the underlying representation which may mutate. For instance, an object can expose a constant accessor which could initialise a member upon first access, which means it must mutate that member even though the object's external state is currently constant with respect to the client. A programmer might do this when initialising a member would be a costly operation, but if the accessor is not invoked against the object then there is no cost. The cost is only paid when the client invokes the accessor for the first time.


Other than a real estate agent, where can I find the current foreclosure list for homes in my area?

Your local tax accessor will be able to give youa listing of forclosed properties in your area.


Encapsulation data we can inherit out side the class?

Yes. If the variables are public yes they can be inherited. If they are private then they cannot be inherited. But to access these private variables you can have accessor methods that are public and can be accessed everywhere.