Answer by Siddharth for Java setter and getter?
Data Hiding and Encapsulation are frequently mistaken for security by first time oops learners. Its important to understand that data hiding and encapsulation have nothing to do with security.These...
View ArticleAnswer by Sid for Java setter and getter?
He was arguing that if "Data Hiding" is an OOP principle then aren't we breaking it by exposing via getters and setters. I think he wanted you to spell out the difference in principle between being...
View ArticleAnswer by PeterMmm for Java setter and getter?
I bet he was waiting that you will refer to "immutable" types also.PD. private is no type, it is an access modifier.
View ArticleAnswer by toto2 for Java setter and getter?
As some answers already pointed out, set/get don't have to actually set or return actual members.For example, let's say you have a Coordinate class with set/get for (x, y). The inner implementation...
View ArticleAnswer by Ionut for Java setter and getter?
protected String name;public void setName(String newName){ if(newName.length() > 5) this.name = newName}public String getName(){ return this.name;}In this simple case the name attribute can be...
View ArticleAnswer by Andreas Dolk for Java setter and getter?
The class fields are hidden, if we declare them private. No doubt (we ignore nasty reflection tricks). If we want to make the values accessible, we provide access methods (getter/setter for...
View ArticleAnswer by user1190541 for Java setter and getter?
Data hiding is bad term, better say data encapsulation. In java access to private members is done through accessors and mutators ( getter and setter), it is all about hiding and controlling access to...
View ArticleAnswer by npinti for Java setter and getter?
What you are talking about seems to be Encapsulation. Basically the getters and setters allow you to expose class variables as you like and hide any others. Getters and Setters also allow you to...
View ArticleAnswer by Andrew Skirrow for Java setter and getter?
Very simple Example:Version 1 of class could have getter like this.public int getTotal() { return total_;}Version 2 could do thispublic int getTotal() { return a + b;}We've changed how the class is...
View ArticleAnswer by 卢声远 Shengyuan Lu for Java setter and getter?
You may think about implement set/get methods in many different ways.
View ArticleAnswer by tartak for Java setter and getter?
If you make the setter & getter public/protected/default, then you could access the private members on different levels .. if you make setter&getter private then the data is really hidden. This...
View ArticleAnswer by kostja for Java setter and getter?
The support for "data hiding" can be explained by the fact that the getter and setter methods are like gateways to the data. It is only by convention - the JavaBeans convention to be exact - that it is...
View ArticleAnswer by mishadoff for Java setter and getter?
Maybe, he mean Encapsulation as information hiding.
View ArticleJava setter and getter?
Everyone knows that Java supports data hiding.I went for an interview. Then interviewer asked me that if Java supports data hiding by using private as datatype.He said if we use setters and getters in...
View Article