Interfacing and Polymorphism
- March 3rd, 2010
- Posted in Uncategorized
- Write comment
*I’m tired of going all over the place to make notes for class so from now on Ill be using this site not only to blog but to keep track of my notes for my classes
TypeCasting
It is possible to type cast a variable that is of type to a different type of object as long as both objects have that interface implemented
eg/
Genital penis = new Genital(9inches);
phalanges thumb = new phalanges();
interface x;
interface x = penis; // changing the value of type Genitals to type interface
thumb = (phalanges) x; // the value that was once type Genitals was converted to type interface and now typecasted to type phalanges
This is ok to do.
Polymorphism
*It is impossible to construct a Measurable object because there is no objects in an interface.
*However it is possible to declare a variable that is of type as long as if the variable is an object that the class of that object “implements” the measurable interface.
*Overloading and polymorphism are both declaring methods of the same name. Overloading is having more than one method in a class of the same name and Polymorphism is having more than one method of the same name in multiple classes.
*the difference between Overloading and Polymorphism is that Overloading chooses which method to use by the compiler were as Polymorphism chooses the method at run time by the Java Virtual Machine
comment test