 <p>if you <em>really</em> want to do this, you could use reflection:</p> <pre><code>Person obj = new Person(); Method method = Person.class.getMethod("getFirstname"); String firstname = method.invoke(obj); </code></pre> <p>but as mentioned in the comments, you better use a map to hold attribute values:</p> <pre><code>class Person { private Map&lt;String,Object&gt; attrs = new HashMap&lt;&gt;(); public void setAttribute(String attr, Object value) { attrs.put(attr,vaue); } public Object getAttribute(String attr) { attrs.get(attr); } } Person person = new Person(); person.setAttribute("firstname","patrick"); String firstname = (String)person.getAttribute("firstname"); </code></pre>