File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return type of method

 
Janki Shah
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

According to k&b covariant type is possible. But this class does not have a Has-A or Is-A relationship.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is no obligation on the return type of the method as long as it follow java syntax rules and compiles. why are you saying that the method cannot return variable of the type Main. the co-variant type is for overridding methods. Overriding is related to inheritance. when a method overriddes another method then the overridding method can have co-variant return type ,which means its return type can be any sub-class of the return type of overridden method. there is nothing stopping you from returning object of another class from your methods.
 
Janki Shah
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Gurpeet for clearing my doubt.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic