Abstract Classes and Such
I am learning about Polymorphism and I am a little confused, can someone respond back with a link or give me an over view on more information about Polymorphism and how it works along its t ype of methods like super class and abstract constructor and such. An abstract constructor is something I really dont understand so hopefully someone can explain that to me at the least of things.
~Infamous Whoo Kid
[418 byte] By [
KnoXNBS1a] at [2007-10-2 5:39:09]

> I am learning about Polymorphism and I am a little
> confused, can someone respond back with a link or
http://java.sun.com/docs/books/tutorial/java/concepts/index.html
http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29
> give me an over view on more information about
> Polymorphism and how it works along its t ype of
> methods like super class and abstract constructor and
> such.
Search for it on the web or read some tutorials. Sorry, but this is too lengthy and tiresome to write down.
> An abstract constructor is something I really
> dont understand so hopefully someone can explain that
> to me at the least of things.
There is no such thing as an abstract c'tor. There's just a c'tor in an abstract class.
Get rid of the notion that a c'tor actually creates an object. It doesn't. "new" does. A c'tor is just a special method that's called after object creation in order to initialize member variables. Since abstract classes can have those, it's not absurd to provide a c'tor, too. Example:
public abstract class Name {
private String firstName;
private String lastName;
protected Super(String first, String last) {
firstName = first;
lastName = last;
}
public abstract String getFullName();
public String getFirstName() {
return firstName;
}
public String getLastName() {
return firstName;
}
}
public class WesternName extends name {
public WesternName(String first, String last) {
super(first, last); // calls the c'tor of Name
}
public String getFullName() {
String fullName = getFirstName() + " " + getLastName();
return fullName;
}
}
public class AsianName extends name {
public WesternName(String first, String last) {
super(first, last); // calls the c'tor of Name
}
public String getFullName() { // returns a different ful name
String fullName = getLastName() + " " + getFirstName();
return fullName;
}
}
That's an example of implementing polymorphism:
Name n = somethingThatGivesMeAName.getName();
System.out.println(n.getFullName);
as it always prints the right full name, regardless if it's western or asian.
And it's an example of the use of a c'tor in an abstract class: to actually set the private fields with values. It's true that Name can not be instantiated, but what's inside it will still be used by it's subclasses.