Sinisterly
Anyone know anything about polymorphism? - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Coding (https://sinister.ly/Forum-Coding--71)
+--- Thread: Anyone know anything about polymorphism? (/Thread-Anyone-know-anything-about-polymorphism)



Anyone know anything about polymorphism? - Inori - 05-19-2015

Next year, I'm taking a course called ICS3UP, or pre-AP Introduction to Computer Sciences. It sounds fancy and makes it look like I'm learning about hardware, but it's pretty much Java and nothing else.
I was talking to my teacher about it, and in the next course, ICS4UP (AP computer science), we learn about polymorphism in object oriented programming (in the sake of efficiency, probably Java). From what I gather, the concept is highly dependant on user-made Classes and Methods, but I was wondering if anyone here had a more solid definition.


RE: Anyone know anything about polymorphism? - 6e6b - 05-27-2015

maybe this site would help? http://www.tutorialspoint.com/java/java_polymorphism.htm

public interface Vegetarian{}
public class Animal{}
public class Deer extends Animal implements Vegetarian{}


Now, the Deer class is considered to be polymorphic since this has multiple inheritance. Following are true for the above example:

A Deer IS-A Animal

A Deer IS-A Vegetarian

A Deer IS-A Deer

A Deer IS-A Object

Better in Code, Definitions are.


RE: Anyone know anything about polymorphism? - Inori - 05-27-2015

(05-27-2015, 01:59 AM)6e6b Wrote: maybe this site would help? http://www.tutorialspoint.com/java/java_polymorphism.htm

public interface Vegetarian{}
public class Animal{}
public class Deer extends Animal implements Vegetarian{}


Now, the Deer class is considered to be polymorphic since this has multiple inheritance. Following are true for the above example:

A Deer IS-A Animal

A Deer IS-A Vegetarian

A Deer IS-A Deer

A Deer IS-A Object

Better in Code, Definitions are.

Thanks, dude. The code you supplied is pretty informative, even with my limited Java knowledge. (However, I figured it out after messing with classes and methods in Ruby)

Just one thing, use code tags ("code" and "/code", replacing the " with square brackets) when writing out code, as it keeps indents intact.


RE: Anyone know anything about polymorphism? - 6e6b - 05-28-2015

Code:
Sweet I forgot that option



RE: Anyone know anything about polymorphism? - Banadmin - 06-11-2015

Polymorphism is what the word stands for. You can morph one object as another as long as it holds the same and/or more attributes as the object you're morphing it into. For example, you could morph a circle into a shape because circle holds the same attributes as shame plus more (if you were to program this!).

Smile