Search Interview Questions | ![]() ![]() Click here and help us by providing the answer. ![]() Click Correct / Improve and please let us know. |
|
| ||||
Core Java - Interview Questions and Answers for 'Setter' - 5 question(s) found - Order By Newest | ||||
| ||||
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. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
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. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
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 ) | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
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. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
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. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||