🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.java.programmer
Article #172

Re: calling method of super class of super class

#172
From: Babu Kalakrishnan
Date: Tue, 01 May 2001 04:42
48 lines
2659 bytes
On Tue, 01 May 2001 00:52:20 GMT, Carsten Friedrich <Carsten.Friedrich@gmx.de> wrote:

>is it possible to call a method of the super class of the super class?
>E.g. (Pseudo java):
>
>Class A { void f() { print "a";}}
>
>Class B extends A { void f() {print "b"};}
>
>Class C extends B { void f() {  A.f();}}
>
>unfortunately Java does not allow me to do it like that (unless f is
>static). Is there another way?

As far as C is concerned, it extends B - and hence inherits only B's
properties. If the method f() has been over-ridden by B, you would
expect to be able to access only B's implementation of f() isn't it ?
Any property that C inherits from A would be only those that B doesn't
override - which makes perfect sense to me.

In case class B wants to provide access to A's method f() to its
descendants and at the same time have its own implementation of f(), I
guess it would need to implement it as another method - say something like :

void ancestorF()
{
    super.f();
}

>I can imagine some workarounds which all have some flaws:
> - reimplement the method from A , problem: the implementation of
>   A.f() might not be known to me.

The reason for needing access to A's implementation of the method isn't
very clear. If you needed that, you'd extend A and not B.

> - Have a class variable 'a' of type 'A' and call 'a.f()', which     
>   wastes memory and does not always work ( A might be abstract)
> and so on ....

And also depending on the implementation details (which is probably
unknown to you), calling the method on a different instance than your
own is unlikely to do the same thing anyway. (For instance if method f()
changed the value of an instance variable x, it would be a.x that
changes, not this.x)


BK
Technical Details
Message-ID: <slrn9esfl2.279.kala@ganga.sankya.com>
Path: arc1-ca.pugleaf.net!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.stealth.net!newsserver.pacific.net.sg!kala
References: <3aee0699.231503@news.usyd.edu.au>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d6db,edae50d7b645c6ea
X-Google-Attributes: gid10d6db,public
X-Google-Thread: 10a146,edae50d7b645c6ea
X-Google-Attributes: gid10a146,public
X-Google-ArrivalTime: 2001-04-30 22:10:11 PST
Path: arc1-ca.pugleaf.net!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.stealth.net!newsserver.pacific.net.sg!kala
From: kala@sankya.com (Babu Kalakrishnan)
Newsgroups: comp.lang.java.programmer,aus.computers.java
Subject: Re: calling method of super class of super class
Date: Tue, 1 May 2001 10:12:10 +0530
Organization: Subscriber of Pacific Internet 
Lines: 48
Message-ID: <slrn9esfl2.279.kala@ganga.sankya.com>
References: <3aee0699.231503@news.usyd.edu.au>
Reply-To: kalakrishnan@vsnl.com
NNTP-Posting-Host: ppp67.bangalore-188.pacific.net.in
User-Agent: slrn/0.9.6.2 (Linux)