Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use Of Interface

 
Biswomohan Pattanaik
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt
//Interface A

I have a doubt,In class C I am accessing the B's add()through 2 referance variables one is class type and another is interface type.ok
My doubt is what's the differance?
which is adviceable to use?


thanks
Biswo
[ November 02, 2008: Message edited by: Maneesh Godbole ]
 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will not see any difference in the output because you have assigned same object to both the references.

Regarding which one is good to use is the the first one

that is A a = new B();

if you have 2 implemntation and at run time you have to decide that which one to be used then 1st is more appropriate.
 
Venkata Kumar
Ranch Hand
Posts: 110
Firefox Browser Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

When interface has reference to a object then only methods declared in the interface can be called.

Here reference to object is via Class name and all the public methods of Class B are accessible.
 
vipin raimcs
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A a = new B(); is advisable to use, this is because of business purpose. Also creation of objects is left on some factory classes. So client code is totally unaware of the fact that what they are using. They just only know if A a.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic