CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2012
    Posts
    1

    Polymorphism without inheritance in java

    Hi,

    Can any one please explain how to implement polymorphism without inheritance in java.
    It would be useful if it is explained starting with what is polymorphism, types of polymorphism and polymosrphism with inheritance and without inheritance.

    Thanks

  2. #2
    Join Date
    May 2009
    Posts
    2,413

    Re: Polymorphism without inheritance in java

    Quote Originally Posted by AmyJose View Post
    how to implement polymorphism
    Polymorphism literally means "many forms" and it's not something you implement really. It's part of the language or rather of the type system of the language. The purpose is to make it more flexible. A monomorphic language would be very tedious to work with.

    in Java there are four different kinds: subtype polymorphism (by the way of inheritance and overriding), parametric polymorphism (basically generics), method overloading and finally coersion (types automatically "sliding" into each other).
    Last edited by nuzzle; June 26th, 2012 at 03:20 PM.

  3. #3
    Join Date
    Nov 2006
    Location
    Barcelona - Catalonia
    Posts
    364

    Re: Polymorphism without inheritance in java

    Quote Originally Posted by AmyJose View Post
    Hi,

    Can any one please explain how to implement polymorphism without inheritance in java.
    It would be useful if it is explained starting with what is polymorphism, types of polymorphism and polymosrphism with inheritance and without inheritance.

    Thanks
    Can't you be a little more specific?
    I don't want to be rude, but if you know nothing about a concept you should first read a manual or a book and then, ask what you don't understand, don't you think?

    This is a good place to get help when you are stuck, when you have a concrete problem or when you don't understand something, but we can't explain how OOP (Object-oriented programming) works, and polymorphism is a basic part of OOP.

    Nevertheless, you can find a very simple self-explanatory example in Wikipedia. You can also check java.util.List interface and their implementations: LinkedList and ArrayList. Both are a good starting point to understand how polymorphism works.

    Albert.
    Please, correct me. I'm just learning.... and sorry for my english :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured