• Post Reply Bookmark Topic Watch Topic
  • New Topic

Polymorphism  RSS feed

 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Animal a = new Dog();

Will this be same as - Dog d = new Dog(); ?
Is there any special for method calling ??
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37469
539
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's different because of what methods you can call.

For example a.bark() will not compile if the method is declared on Dog while d.bark() will. In other words, you can only call the methods available on the variable reference type without casting.
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
I knew I was forgetting something important
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!