• Post Reply Bookmark Topic Watch Topic
  • New Topic

Polymorpic Doubt  RSS feed

 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a very small doubt within me which i wanted to be clear on. The question is on Polymorphism.

Lets say i have 2 class A and B respectively. if i have the below line of code :



The understanding which i have from what i have read is method1 in class B would be called since at runtime new is called on class B and reference variable is of class A.

Then i dont understand how this is possible ? Now lets say :



Now this should have not worked, since removeAll is not there in ArrayList class, can someone please help me with this doubt ?

Thanks in advance,
Yogendra N Joshi.
 
Vijitha Kumara
Bartender
Posts: 4001
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yogendra Joshi wrote:Now this should have not worked, since removeAll is not there in ArrayList class, can someone please help me with this doubt ?


How about the one inherited from AbstractCollection ?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!