Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Biswomohan Pattanaik
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic