From: cindy <inf...@pi...> - 2001-03-26 13:17:43
|
Hi, The book I'm using to learn Java has a statement in one of its examples that is "super(title)". This statement is in a module that extends Frame. What qualifiers do I need for "super" and what do I have to import? Thanks. Wayne |
From: D-Man <ds...@ri...> - 2001-03-26 15:17:53
|
On Mon, Mar 26, 2001 at 09:21:19PM -0500, cindy wrote: | Hi, | The book I'm using to learn Java has a statement | in one of its examples that is "super(title)". | This statement is in a module that extends Frame. What | qualifiers do I need for "super" and what do I have to import? Java only supports single inheritance. "super" is a keyword in Java that refers to a super class of the current class (the first super class with the specified method). Here is an example, first in Java then Python (Jython -- same grammar): public class MyFrame extends java.awt.Frame { /** * A ctor for this class. Must call Frame's ctor to init it as * well. */ public MyFrame( ) { // call java.awt.Frame's ctor super( ) ; } } # bring the "java" module into the current namespace import java class MyFrame( java.awt.Frame ) : # A initializer (ctor) for this class. Must call Frame's ctor to # init it as well. def __init__( self ) : # call the java.awt.Frame's ctor java.awt.Frame.__init__( self ) The main difference is that Python supports multiple inheritance. Thus the meaning of "super" in python isn't quite clear and if a particular meaning is settled on it may not work as expected/intended in some cases. As a result python's designers didn't include "super" as a keyword, but instead you have to specify the super class explicitly by name. The end result is the same, just a liitle different look to the code. BTW, I just tested the python part, and Jython very nicely translated the python idiom of calling __init__ into the java ctor of Frame (as obviously java.awt.Frame doesn't have a method named __init__). HTH, -D |
From: Sarwar R. <raz...@ya...> - 2001-03-26 21:26:55
|
The super method is invoked implicitly on the current object. Hence super(title) is equivalent to this.super(title). All you're doing is calling the superclass (in this case Frame) constructor. You do not need to import any classes for this functionality; all subclasses have access to their superclasses using this construct. -Sarwar --- cindy <inf...@pi...> wrote: > Hi, > The book I'm using to learn Java has a statement > in one of its examples that is "super(title)". > This statement is in a module that extends Frame. > What > qualifiers do I need for "super" and what do I have > to import? > Thanks. > Wayne > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > http://lists.sourceforge.net/lists/listinfo/jython-users ===== ************************* Sarwar S Raza NMS Software Engineer CommWorks Corporation http://www.wpi.edu/~sraza ************************* __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ |