Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7667
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!novia!news-out.readnews.com!transit4.readnews.com!postnews.google.com!s2g2000vby.googlegroups.com!not-for-mail |
|---|---|
| From | Ethan <sam_cit@yahoo.co.in> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Avoid derived class to override a method yet should allow callers to invoke the method |
| Date | Tue, 6 Sep 2011 22:40:22 -0700 (PDT) |
| Organization | http://groups.google.com |
| Lines | 51 |
| Message-ID | <1e0a57fd-cd79-45d8-ab37-252b981e3dfe@s2g2000vby.googlegroups.com> (permalink) |
| References | <79cc1af8-1f3c-41c7-bbe2-8c5085b25e7c@t9g2000yqi.googlegroups.com> <38560bc6-af42-471f-b750-d2966452b1c3@glegroupsg2000goo.googlegroups.com> |
| NNTP-Posting-Host | 75.62.204.165 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | posting.google.com 1315374823 6050 127.0.0.1 (7 Sep 2011 05:53:43 GMT) |
| X-Complaints-To | groups-abuse@google.com |
| NNTP-Posting-Date | Wed, 7 Sep 2011 05:53:43 +0000 (UTC) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | s2g2000vby.googlegroups.com; posting-host=75.62.204.165; posting-account=_beFiwoAAAA_k1fgJtZfPVQP5wnC7Wyf |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-Header-Order | HNKRUAELSC |
| X-HTTP-UserAgent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1,gzip(gfe) |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7667 |
Show key headers only | View raw
On Sep 6, 9:40 pm, Lew <lewbl...@gmail.com> wrote:
> Ethan wrote:
> > I have a requirement where base class has method (implemented) and
> > derived class shouldn't be able to override it.
> > However, the method needs to be invoked by a caller who creates an
> > instance of the derived class.
>
> > Is this possible?
>
> Absolutely.
>
> You prevent an override by 'final' in the method signature, and this is very frequently The Right Thing To Do.
>
> You make the method callable by client code through 'public' in the method signature, which is the standard thing to do.
>
> public class BaseOfOperations
> {
> public final void DoSomething()
> {
> // implementation here
> }
>
> }
>
> public class SpecificOperations extends BaseOfOperations
> {
> // cannot override DoSomething()
>
> }
>
> public class Client
> {
> public void Whatever()
> {
> BaseOfOperations boo = new SpecificOperations();
> boo.DoSomething();
> }
>
> }
>
> I suggest that you read the Java tutorials and a good basic book on Java programming.http://download.oracle.com/javase/tutorial/
>
> --
> Lew
Thanks Lew and Peter. Its been a while that i have coded in java and
didn't knew much about final.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Avoid derived class to override a method yet should allow callers to invoke the method Ethan <sam_cit@yahoo.co.in> - 2011-09-06 21:05 -0700
Re: Avoid derived class to override a method yet should allow callers to invoke the method Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-09-06 21:38 -0700
Re: Avoid derived class to override a method yet should allow callers to invoke the method Lew <lewbloch@gmail.com> - 2011-09-06 21:40 -0700
Re: Avoid derived class to override a method yet should allow callers to invoke the method Ethan <sam_cit@yahoo.co.in> - 2011-09-06 22:40 -0700
Re: Avoid derived class to override a method yet should allow callers to invoke the method Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-09-07 10:35 +0000
Re: Avoid derived class to override a method yet should allow callers to invoke the method Lew <lewbloch@gmail.com> - 2011-09-07 08:14 -0700
csiph-web