Quantcast
Channel: Java setter and getter? - Stack Overflow
Browsing latest articles
Browse All 14 View Live

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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article


Answer by 卢声远 Shengyuan Lu for Java setter and getter?

You may think about implement set/get methods in many different ways.

View Article

Answer 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 Article

Answer 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 Article

Answer by mishadoff for Java setter and getter?

Maybe, he mean Encapsulation as information hiding.

View Article


Java 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
Browsing latest articles
Browse All 14 View Live