Is it correct to assume that Property in Java it is simple getter and setter?
Asked
Active
Viewed 114 times
-5
-
Most adhere to the [JavaBean standard](http://en.wikipedia.org/wiki/JavaBeans) -- `public void setSecret(String secret)`, and `public String getSecret()` – Hovercraft Full Of Eels Nov 04 '14 at 17:54
-
Yes, I know it. But what is property here? A `method`? – Alex Nov 04 '14 at 17:55
-
1Are you asking how to define a property in C#? Or how to write a C# property like a Java one? – BradleyDotNET Nov 04 '14 at 17:55
-
No. I'm asking about property in Java. – Alex Nov 04 '14 at 17:56
-
Tag's been removed. Thanks. – Alex Nov 04 '14 at 17:57
-
Yes, a Java property is a private field with a getter/setter pair. – meskobalazs Nov 04 '14 at 17:57
-
Are you sure about that? – Alex Nov 04 '14 at 17:59
-
Have been answer on here: http://stackoverflow.com/questions/70471/no-properties-in-java – Crazenezz Nov 04 '14 at 18:01
-
may it will help you. http://stackoverflow.com/questions/10115588/what-is-the-difference-between-field-variable-attribute-and-property-in-java – Nov 04 '14 at 18:16
2 Answers
3
As @Hovercraft Full of Eels mentioned, standard Java Beans appear to have properties (provided by getter and setter methods), but Properties do not exist in Java as they exist in C# (see question No Properties in Java)
0
In your example there are just a field named secret
and two methods named property
.
You can have two methods with the same name in java because this language supports polymorphism.
There is an important condition, the two methods can have the same name but not the same signature, parameters and/or return type should be differents.
You can find more information about polymorphism in java here : polymorphism in java

Tyoras
- 26
- 1
- 4
-
My question is not about polymorphism. It's about properties in Java as part of language. – Alex Nov 04 '14 at 18:39
-
Ok, so the best answer is eurythmia's one : Properties do not exist in Java as they exist in C# – Tyoras Nov 05 '14 at 11:05