aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How to user polymophism?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How to user polymophism??" Watch "How to user polymophism??" New topic
Author

How to user polymophism??

qionghua yang
Ranch Hand

Joined: Oct 31, 2000
Posts: 68
Hi there,
I would like to have an abstract method in my base class. And I would like it to be a static method. But when I compile I get the error message "illegal combinatio of the accessor". Is it true that static can't be with abstract? Can someone explain to me why?
********My code******************
public abstract class superClass
{
public superClass()
{
}
//super abstract method
abstract public static String getName();
}
public class subClass
{
public subClass()
{
}
public static String getName()
{
return "SubClass";
}
}

Thanks, qionghua
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
HI,
As I understand it:
Abstract -- subclasses will provide implementation of method
Static -- can not be overridden only hidden by subclasses
Therefore, since we can't override the abstract method Java will not let us place both static and abstract together.
For example:

If static methods could be overridden then we would have expected the output of "Inside Class B" twice.
Regards,
Manfred.
qionghua yang
Ranch Hand

Joined: Oct 31, 2000
Posts: 68
Thanks.
So I got it now. If a method is a static method, it can't be overriden by derived class. But then in this case, how can I implement the polymorphism?
qionghua
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to user polymophism??