Core Java - Interview Questions and Answers for 'Setter' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'Setter' - 5 question(s) found - Order By Rating

 Q1. What is setter injection ?Spring
Ans. Setter Injection in Spring is a type of dependency injection in which the framework injects the dependent objects into the client using a setter method.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     setter injection   dependency injection     Asked in 2 Companies


 Q2. What is a mutator in Java?Core Java
Ans. Mutator is another name for setter methods, i.e the method allows for mutating the property of an object and eventually the state of the object.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     setter method  mutator


 Q3. Is it advisable to set the member variables through constructors instead of setting them through setters ?
Ans. Yes , If the values to be set are known at the time of initialization and doesn't involve polymorphic behavior.If it's using Dependency Injection , then Constructor injection must be available. If it suffice the above conditions, then definitely its advisable to have them set through constructor as they eagerly load the values into the memory and save it fro multiple values assignment ( one through default constructor and then through assignment )

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     constructor  setter vs constructor


 Q4. What ate the getter and setter methods ?
Ans. getters and setters methods are used to store and manipulate the private variables in java beans. A getters as it has name, suggest retrieves the attribute of the same name. A setters are allows you to set the values of the attributes.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   java beans   getter   setter


 Q5. Why are Getter and Setter better than directly changing and retrieving fields ?

or

What is the significance of variable hiding in Java ?

or

Why it's preferred to keep variables private and allow their access through getter and setter methods ?
Core Java
Ans. 1. Methods can participate in runtime polymorphism whereas member variables cannot.

For example -

Vehicle vehicle = new Car();

car.getObjVariable();// will return variable defined in Car

whereas

car.variable

will return the variable from Car class irrespective of the object it holds.

2. Validations can be performed before setting the variables.

3. If the input format changes or some other value or calculated value needs to be returned , that can be absorbed by making change ( wrapping ) in the setter and getter. By this the call to method from outside or interface to the object will remain the same.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   beans   getter   setter



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: