What is the use of passing object to another class reference in java? -


for example: foo ab=new dog();

saving object of type class reference of class!

it's not necessary foo foo = new bar() it's recommendable refer interface , not implementation. way can change implementation without needing change other code. example if you're doing lists , use arraylists might do:

arraylist<integer> numbers = new arraylist<>(); //do stuff numbers 

however might not care kind of list you're better off with

list<integer> numbers = new arraylist<>(); //do stuff numbers 

now doesn't matter kind of list you've got , maybe find you'll better performance linkedlist , can use instead of changing other code.

i polymorphism important when receiving objects other callers though.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -