Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Checking Object Type

 
Ranch Hand
Posts: 765
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
Suppose we recieve object as a parameter.The there is two ways for checkink object type.
1: By its(objects) class.
2: By it's(objetcs) interface.
What is the difference between above two methods.And which method is used in real word applications?
Thanks in advance.
Viki
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it depends how you are use the objects in your system/program. For example - you have the different objects with the same interface and the interface provide the operation doSomething(). When you get the object with this interface, it doesn't metter how doSomething() was implemented, you can call it.
If you are interesting in realisation of the some class, wich provide the special realisation of doSomething(), then you have to check if the object was instanced from the class you need.

for example:
interface theName
sayName()
class myName extends theName
class yourName extends theName
so if it doesn't metter who's name to say ;-) check the interface and call method sayName
if you are expacting to hear your name check if the object type is yourName
and the using of interfaces is the main approach of the object-oriented programming.
my best regards

Originally posted by Vikrama Sanjeeva:
Hi friends,
Suppose we recieve object as a parameter.The there is two ways for checkink object type.
1: By its(objects) class.
2: By it's(objetcs) interface.
What is the difference between above two methods.And which method is used in real word applications?
Thanks in advance.
Viki


 
Sergej Sander
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
read extends like implements in the las posting ;-)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!