• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Use Of Interface

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 110
Firefox Browser MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Yup, yup, yup. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic