I have an assignment where I should write a Java abstract class which will be the base to calculate some points of a competition. The points are assign different depending on weather the person is a boy,girl,man or woman. I wrote the abstract class and then a class for each one of the groups. When I tried to write the test I get error messages for each of the groups that says: cannot resolve symbol constructor Girl(java.lang. String, java.lang.String) This piece is not finish yet, I just do not know what to do. If anyone knows where I can find a good reading on abstract class that will be helpful too. I do not have the concept clear. Any help will be gratly appreciated. Thanks, Nancy This is the code I wrote:
Assuming you know the type of object you will be dealing with at compile time, you could have something like this: - an abstract Rewards class, with an abstract calculate method - four implementations of this class, one for each type of person. - an abstract class (or interface) Person - four implementations of this class If you have this you can write:
If you don't know which type of person you will be dealing with till run time, you'll need a factory class as well. The you can write:
All you need to remember about abstract classes is they are basically templates - they don't necessarily do anything, but they do force all subclasses to do something - in this case implement a calculate method.
If you declare a class "abstract" then it cannot be instantiated. That is you can't make an instance of it. The diffrence between an abstract class and a interface is that an abstract class can have none abstract methods. If you should make a abstract class of a man,woman,boy,etc then you should try to locate something that they all have incommon. Ears, Eyes, head, neck, body, and so on. In an abstract class you can return values in a method
if you had a abstract method in the abstract class then you would force the Girl class to include the method.
Here you would have a compile error because the Girl class didn't include the getName method. It's up to the Girl class to supply the implementation of the getName() method. Hope this make sence. There are probably experienced java programmers that would explain this more clearly. // Mathias