Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #562

Re: Instantiate an abstract class

From Wojtek <nowhere@a.com>
Newsgroups comp.lang.java.help
Subject Re: Instantiate an abstract class
Date 2011-04-06 12:41 -0700
Organization NewsGuy - Unlimited Usenet $19.95
Message-ID <mn.32f97db4f2cae5cc.70216@a.com> (permalink)
References <61c7300d-6011-4639-a5f1-5cd4c58906fa@r4g2000prm.googlegroups.com>

Show all headers | View raw


Rob McDonald wrote :
> abstract class AFoo {
>   void doStuff() {

      AFoo a = getNewInstance();

>   }

public absract AFoo getNewInstance();

> }
>
> class Bar extends AFoo {

@Overrides
public Bar getNewInstance()
{
  return new Bar();
}


> }
>
> class Fred extends AFoo {

@Overrides
public Fred getNewInstance()
{
  return new Fred();
}


> }

So "AFoo a" will hold an instance of whatever class extends AFoo, yet 
it can be cast into the subclass.

-- 
Wojtek :-)

Back to comp.lang.java.help | Previous | NextPrevious in thread | Find similar


Thread

Instantiate an abstract class Rob McDonald <rob.a.mcdonald@gmail.com> - 2011-04-05 14:14 -0700
  Re: Instantiate an abstract class Patricia Shanahan <pats@acm.org> - 2011-04-05 14:37 -0700
    Re: Instantiate an abstract class Rob McDonald <rob.a.mcdonald@gmail.com> - 2011-04-05 14:49 -0700
  Re: Instantiate an abstract class Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-04-05 17:48 -0400
    Re: Instantiate an abstract class Rob McDonald <rob.a.mcdonald@gmail.com> - 2011-04-05 14:54 -0700
      Re: Instantiate an abstract class Patricia Shanahan <pats@acm.org> - 2011-04-05 15:09 -0700
      Re: Instantiate an abstract class Lew <noone@lewscanon.com> - 2011-04-06 12:43 -0400
        Re: Instantiate an abstract class "John B. Matthews" <nospam@nospam.invalid> - 2011-04-06 22:07 -0400
  Re: Instantiate an abstract class Roedy Green <see_website@mindprod.com.invalid> - 2011-04-05 19:02 -0700
  Re: Instantiate an abstract class Roedy Green <see_website@mindprod.com.invalid> - 2011-04-05 19:42 -0700
  Re: Instantiate an abstract class Lothar Kimmeringer <news200709@kimmeringer.de> - 2011-04-06 18:26 +0200
    Re: Instantiate an abstract class Lew <noone@lewscanon.com> - 2011-04-06 12:49 -0400
      Re: Instantiate an abstract class Patricia Shanahan <pats@acm.org> - 2011-04-06 10:09 -0700
      Re: Instantiate an abstract class Lothar Kimmeringer <news200709@kimmeringer.de> - 2011-04-07 01:01 +0200
  Re: Instantiate an abstract class Wojtek <nowhere@a.com> - 2011-04-06 12:41 -0700

csiph-web