🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8399

Re: Is "return super;" a valid statement

#8399
From: Valentino Kyriakides
Date: Mon, 19 Mar 2001 11:49
103 lines
3113 bytes
Seems you mixed up Smalltalk and Java?

Smalltalk:
--------------

When an object sends a message to super, it is saying in effect "I don't
want to invoke my own definition of this method, I want to invoke my
superclass's definition." This is useful so that inheritance and over-riding
can be used to *extend* a superclass's method in a subclass, instead of just
to *replace* it. In other words, a subclass would define a method with the
same name as a method in it's superclass. This method might call the
superclass's method (using super method...) and then do some extra
processing itself.

Example:  super method: args


Java related:
------------------

In Java you can call "super() or super(...)" only inside of constructors and
AFAIK it has always to be the first expression inside a constructor, e.g.:

    class A {
       int i;

       public A() {
          // implicit call of super
          i = 3;
       }
    }

    class B extends A {
         // uses automat. the standardconstructor -->  public B() {
super(); }
    }



In order to call some superclass's method in general, use:

    super.methodname(...);


Valentino


"Ralph Quapp" <-> schrieb im Newsbeitrag news:3ab26402$1_1@dnews...
> Hello,
>
> I encountered a compile error in one of my classes when using the
statement
> "return super;" and compiling it with javac or jikes. JBuilder does not
> complain. In my example doSomething() in class B contains this statement.
>
> The error reported is:
>
> Error in file ReturnType.java at line 31, column 37: '.' expected
>
> I am wondering now whether the statement is valid or not? And of course
why?
>
> regards Ralph
>
>
> public class ReturnType
> {
>
>  public class A
>  {
>   public String a = "A";
>
>   public A doSomething()
>   {
>    return this;
>   }
>  }
>
>  public class B extends A
>  {
>   public String b = "B";
>
>   public A doSomething()
>   {
>    return super;                    <---- error
>   }
>  }
>
>
>  public ReturnType()
>  {
>   B b = new B();
>
>   A a = b.doSomething();
>  }
>
>  public static void main(String[] args)
>  {
>   ReturnType r = new ReturnType();
>  }
> }
>
>
Technical Details
Message-ID: <3ab5f2e6_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!128.230.129.106!news.maxwell.syr.edu!nntp1.njy.teleglobe.net!teleglobe.net!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnews!194.64.62.36
References: <3ab26402$1_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,a2b6df84216d25a2
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-03-23 03:33:38 PST
From: "Valentino Kyriakides" <vkyr@lavielle.com>
Newsgroups: borland.public.jbuilder.java.language
References: <3ab26402$1_1@dnews>
Subject: Re: Is "return super;" a valid statement
Date: Mon, 19 Mar 2001 12:49:06 +0100
Lines: 105
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
NNTP-Posting-Host: 194.64.62.36
Message-ID: <3ab5f2e6_1@dnews>
X-Trace: 19 Mar 2001 03:52:06 -0800, 194.64.62.36
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!128.230.129.106!news.maxwell.syr.edu!nntp1.njy.teleglobe.net!teleglobe.net!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnews!194.64.62.36