• 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

Memory Allocation and Benifit of an Interface Referance Variable over class referance

 
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

code:
--------------------------------------------------------------------------------

interface A{public void add();public void sub();public void multiplication();} //Class B that Implements Aclass B implements A{public void add(){ int a=30; int b=40; int c=a+b; System.out.println("The result of Addition is:-"c); }public void sub(){ int a=80; int b=40; int c=a-b; System.out.println("The result of Substraction is:-"c);}public void multiplication(){ int a=80; int b=40; int c=a*b; System.out.println("The result of Multiplication is:-"c);}public void division(){ int a=80; int b=40; int c=a/b; System.out.println("The result of Division is:-"c); }}//Anaother class C that use B's methodclass C{public static void main(String[]args){ //what is the differnce //I have a doubt why we use this line A a=new B(); a.add(); B b=new B(); b.add(); }}

--------------------------------------------------------------------------------


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
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll just let you know that you're not going to get many responses with your code formatted that way. Try again with properly formatted code. Use [code ][/code ] (without the spaces) tags to preserve the formatting of your code.
reply
    Bookmark Topic Watch Topic
  • New Topic