aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help in generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help in generics" Watch "Help in generics" New topic
Author

Help in generics

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
Hi, Could someone please help me understand the below concept :

"An ArrayList<Animal> can accept references of type Dog, Cat, or any other subtype of Animal (subclass, or if Animal is an interface, implementation)."


Additionally could someone please point me to understand any good link for understanding the concepts used in Generics.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3177
    
  47

In simple terms, if there is a reference like "ArrayList<Animal> anim", you can add a dog, cat, cow, or any other animal into that object, using the add(-) method. You may have a look at the Sun Generics tutorial.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hello jose,

Check JavaGenericsFaq

Hope this helps,


Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help in generics