From: <ge...@ya...> - 2003-01-05 21:51:45
|
I'm having some problems extending an abstract Java class. Everything is fine, except when the extended class is called from within the constructor. First of all is my Abstract Java class. ----------------------------------------------------------- 01 public abstract class Abstract { 02 03 public Abstract() { 04 System.out.println("Java Class Abstract Constructing"); 05 // showInt(5); 06 System.out.println("Java Class Abstract Constructed"); 07 } 08 09 public abstract void showInt(int i); 10 11 public void showSix() { 12 showInt(6); 13 } 10 } --------------------------------------------- Abstract.java My Jython script looks like this. ----------------------------------------------------------- 01 import Abstract 02 03 class extends(Abstract): 04 05 def __init__(self): 06 print "Jython class 'extends' initialised" 07 08 def showInt(self, i): 09 print "showInt called with : ", i 10 11 12 x = extends() 13 x.showInt(6) 14 x.showSix() ------------------------------------------------ Extends.jy The output is as expected: Jython class 'extends' initialised Java Class Abstract Constructing Java Class Abstract Constructed showInt called with : 6 showInt called with : 6 However, if I decomment line 5 in Abstract.java, so that the system attempts to call the abstract method in the constructor the output is an error: Jython class 'extends' initialised Java Class Abstract Constructing Traceback (innermost last): File "D:\gedbs\Java\lib\uk\co\RushCoding\extend.jy", line 12, in ? AttributeError: abstract method "showInt" not implemented Obviously this can be solved by using an explicitly called init() function rather than the constructor, but since I'm actually extended a public api I'd prefer to avoid this. Is there any way of calling an extended abstract method in the constructor, or preventing the abstract classes default constructor from being called? __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com |