• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

basic question about method calls

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why we make obj.getClass().getName() call? I understand that this will return the name of the class, but my question is why is the syntex the way it is, i mean getClass method calls getName method.
where this type of call is used ?
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have an object and do a getClass() on it, it will return another object of the Class class. If you look in the API for Class you will see that it has a method getName() that returns a String representation of the class.
you COULD have split that syntax up into 2 statements:
Class c = obj.getClass();
String s = c.getName();
But it is more streamlined to weld it all together.
String s = obj.getClass().getName();
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at how JavaBeans work. All properties are encapsulated in getXX and setXX methods. Whenever you see a getSomething() method, you know it will simply give you the Something property on the object. Any calls from there, eg xx.getSomething().runAway("fast"); are methods on the object that getSomething() gave you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!