Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

query

 
ajay Kumar Rana
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we pass a reference of subclass to a method which has parameter of superclass type.
 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Java Ranch,

Can we pass a reference of subclass to a method which has parameter of superclass type.


Yes. In fact it is generally good to use a more abstract class or even an interface which is more abstract as parameters because this makes your method more general.

Kaydell
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic