wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Memory Allocation and Benifit of an Interface Referance Variable over class referance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Memory Allocation and Benifit of an Interface Referance Variable over class referance" Watch "Memory Allocation and Benifit of an Interface Referance Variable over class referance" New topic
Author

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

Biswomohan Pattanaik
Greenhorn

Joined: Feb 22, 2008
Posts: 10
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

Joined: Jan 17, 2006
Posts: 1296
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.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Memory Allocation and Benifit of an Interface Referance Variable over class referance
 
Similar Threads
Doubt in inheritance
doubt in interface
Doubt on interface
Inheritance doubt
Use Of Interface