Abstract class instantiation.?

I have an Abstract class which is extended
My question is:
How can the Abstract class be instantiated:
Animal[] ref = new Animal[3];
In Java,we cannot instantiate Abstract class,so how does this
work
abstract class Animal  // class is abstract
  private String name;
  public String getName(){       
       return name;
  public abstract void speak();  
class Dog extends Animal{
      private String dogName;
      public Dog(String nm){
     this.dogName=nm;
      public void speak(){       // Implement the abstract method.
      System.out.println("Woof");
      public String getName(){   // Override default functionality.
          return dogName;
class Cow extends Animal{
      private String cowName;
      public Cow(String nm){
      this.cowName = nm;
      public void speak(){       // Implement the abstract method.
      System.out.println("Moo");
      public String getName(){
          return cowName;
public class AnimalArray{
  public static void main(String[] args) {
  Animal[] ref = new Animal[3]; // assign space for array
  Dog aDog = new Dog("Rover");  // makes specific objects
  Cow aCow = new Cow("Bossy"); 
  // now put them in an array
  ref[0] = aDog;
  ref[1] = aCow;
  // now dynamic method binding
  for (int x=0;x<2;++x){
       ref[x].speak();
       System.out.println(ref[x].getName());
}

You mean to say that now we have a handle or a reference to the
abstract class. Right ?
But in the
public static Test instance () {
        return new Test () {
            public void test () {}
    }How can you say 'return new Test()' as Test is an abtract class
and what will public void test() return as this has no body ?

Similar Messages

  • Abstract Class can't be instantiated

    Hi I'm getting the following error messages while compiling. Does any one have any idea how to get RID of it?
    ERROR MESSAGES:
    EditableHeaderTableExample2.java:48: inner class EditableHeaderTableExample2. MyComboRenderer is an abstract class. It can't be instantiated.
    MyComboRenderer renderer = new MyComboRenderer(items);
    ^
    EditableHeaderTableExample2.java:79: Method redefined with different return type: javax.swing.table.TableCellRenderer getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int) was java.awt.Component getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
    public TableCellRenderer getTableCellRendererComponent(
    ^
    2 errors
    Here is the code:
    EditableHeaderTableExample2.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.JComponent;
    import javax.swing.JComboBox;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    import javax.swing.JTable;
    import javax.swing.plaf.metal.*;
    import javax.swing.JFrame;
    import javax.swing.table.TableColumn;
    import javax.swing.table.TableColumnModel;
    import javax.swing.DefaultCellEditor;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.DefaultTableCellRenderer;
    public class EditableHeaderTableExample2 extends JFrame {
    public static void main(String[] args) {
    EditableHeaderTableExample2 frame = new EditableHeaderTableExample2();
    frame.setSize(400,300);
         frame.setLocation(100,100);
         frame.setVisible(true);
    public EditableHeaderTableExample2(){
    JTable table = new JTable(10,10);
    TableColumnModel columnModel = table.getColumnModel();
    table.setTableHeader(new EditableHeader(columnModel));
    String[] items = {"Dog","Cat"};
    JComboBox combo = new JComboBox();
    for (int i=0;i<items.length;i++) {
    combo.addItem(items);
    MyComboRenderer renderer = new MyComboRenderer(items);
    EditableHeaderTableColumn col;
    // column 1
    col = (EditableHeaderTableColumn)table.getColumnModel().getColumn(1);
    col.setHeaderValue(combo.getItemAt(0));
    col.setHeaderRenderer(renderer);
    col.setHeaderEditor(new DefaultCellEditor(combo));
    // column 3
    col = (EditableHeaderTableColumn)table.getColumnModel().getColumn(3);
    col.setHeaderValue(combo.getItemAt(0));
    //col.setHeaderRenderer(renderer);
    col.setHeaderEditor(new DefaultCellEditor(combo));
    JScrollPane pane = new JScrollPane(table);
    getContentPane().add(pane);
    class MyComboRenderer extends JComboBox implements TableCellRenderer
    MyComboRenderer(String[] items) {
    for (int i=0;i<items.length;i++) {
    addItem(items[i]);
    public TableCellRenderer getTableCellRendererComponent(
    JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column) {
    setSelectedItem(value);
    return this;

    This is not a suggestion, it's a requirement. When you say
    class MyComboRenderer extends JComboBox implements TableCellRendererthe "implements TableCellRenderer" part is a promise that your class will include a method whose signature is
        Component getTableCellRendererComponent(JTable table, Object value,
                                 boolean isSelected, boolean hasFocus,
                                 int row, int column);

  • About  "abstract class cannot have be instantiated"

    in java coding it means
    ========
    abstract  class X
      public X();
    }========
    no {} is allowed to public X
    or i can not write a invoke as
    ========
    X x=new X();========
    or both of them are forbidden by abstract class?
    why body{} is related to instantiated?
    why a abstract class can not has a static method?

    in java coding it means
    ========
    abstract class X
    public X();
    ========
    no {} is allowed to public X???
    You must include the braces for the constructor. The code you have posted won't compile.
    or i can not write a invoke as
    ========
    X x=new X();
    ========Correct. You need to provide the implementation first, which can be as simple as "X x = new X() { };".
    why body{} is related to instantiated?It's not.
    why a abstract class can not has a static method?It can. Try writing some of your own tests to validate your (incorrect) assumptions.
    Example:abstract class X
      public X() { };
      static void foo() {};
    }

  • ".. is an abstract class.  It can't be instantiated"

    Does anyone have an idea of how I can get rid of the above error message? Here is a bit of my code:
    import java.io.*;
    import java.util.Vector;
    class Project3 {
    private BiTree company = new BiTree();
    public static void main(String[] args) throws IOException {
    Project3 run = new Project3();
    run.Command();
    public void Command() throws IOException {}
    public interface comparable {
    //not sure if need this in this class, or at all
    public int compare(Object object1,Object object2);
    public void add() {
    Employee newOne = new Employee();
    System.out.println("Enter name");
    BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));;
    String name = stdin.readLine();
    System.out.println("Enter title");
    BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));;
    String title = stdin.readLine();
    System.out.println("Enter payrate");
    BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));;
    payrate = Double.parseDouble.stdin.readLine();
    newOne.setTitle(title);
    newOne.setName(name);
    newOne.setPayrate(payrate);
    company.insert(newOne);
    }

    It is not possible to create instances of an abstract class.
    I hope this example helps,
    abstract class Vehicle
    public static void main(String arg[])
    Vehicle a;
    a = new Automobile(); // ok, since Automobile is a kind of Vehicle
    // The class Automobile, a special case of Vehicle
    class Automobile extends Vehicle

  • Casting & abstract class & final method

    what is casting abstract class & final method  in ABAP Objects  give   some scenario where  actually  use these.

    Hi Sri,
    I'm not sure we can be any more clear.
    An Abstract class can not be instantiated. It can only be used as the superclass for it's subclasses. In other words it <b>can only be inherited</b>.
    A Final class cannot be the superclass for a subclass. In other words <b>it cannot be inherited.</b>
    I recommend the book <a href="http://www.sappress.com/product.cfm?account=&product=H1934">ABAP Objects: ABAP Programming in SAP NetWeaver</a>
    Cheers
    Graham

  • Non-abstract methods in a Abstract class

    Abstract Class can contain Non-abstract methods.
    and Abstract Classes are not instantiable as well
    So,
    What is the purpose of Non-abstract methods in a Abstract class.
    since we can't create objects and use it
    so these non-abstract methods are only available to subclasses.
    (if the subclass is not marked as abstract)
    is that the advantage that has.(availability in subclass)
    ??

    For example, the AbstractCollection class (in
    java.util) provides an implementation for many of the
    methods defined in the Collection interface.
    Subclasses only have to implement a few more methods
    to fulfill the Collection contract. Subclasses may
    also choose to override the AbstractCollection
    functionality if - for example - they know how to
    provide an optimized implementation based on
    characteristics of the actual subclass.Another example is the abstract class MouseAdapter that implements MouseListener, MouseWheelListener, MouseMotionListener, and that you can use instead of these interfaces when you want to react to one or two types of events only.
    Quoting the javadocs: "If you implement the MouseListener, MouseMotionListener interface, you have to define all of the methods in it. This abstract class defines null methods for them all, so you can only have to define methods for events you care about."

  • Beginner CORBA idl struct said to be abstract class

    How do I instantiate a class declared in my .idl file for use by the methods implementing the interface?
    I want to return an array of Record objects in my CORBA implentation, and my .idl file has:  struct Record
        long recordNumber;
        string firstName;
        string lastName;
        string streetAddress;
        string city;
        string country;
        string phone;
        string eMail;
        string fax;
         typedef sequence <Record> recordSet;
      interface AddRecord
        void setUser(in string user);
        string getUser();
            recordSet getRecords();
    // plus more stuffWhen my implementing class in the server tries to define the getRecords() method like so:  public Record[] getRecords()
        Record r = null;
        Record[] allRecs;
        int index = 0;
        String selectAll = "SELECT * FROM Record ORDER BY Record_number";
        try
          Statement s = connection.createStatement();
          ResultSet recs = s.executeQuery(selectAll);
          while(recs.next())
            index++;
          allRecs = new Record[index];
    //plus more stuffthe compiler complains
    C:\My Documents\Java\CIS 290\hw5\RecordObj.java:178: Record is abstract; cannot be instantiated
    r = new Record();
    I went into the Record.java that the idlj compiler generated, and it is a final, non-abstract class. What incantation do I need here?

    Whoops; solved that one; the real question is this: My .idl file declares some methods that I want to call in my implementation, but the .java class generated by the idlj compiler doesn't show the methods. Here's the full idl:module hw5Corba
    typedef sequence <string> columns;
      struct Record
        long recordNumber;
        string firstName;
        string lastName;
        string streetAddress;
        string city;
        string country;
        string phone;
        string eMail;
        string fax;
       typedef sequence <Record> recordSet;
      interface AddRecord
       void setUser(in string user);
        string getUser();
       recordSet getRecords();
        columns getColumnNames(in string user);
        void newRecord(in Record r);
        void deleteRecord(in long num);
        void updateRecord(in Record r);
        void setRecordNumber(in long num);
        long getRecordNumber();
        void setFirstName(in string first);
        string getFirstName();
        void setLastName(in string last);
        string getLastName();
        void setStreetAddr(in string add);
        string getStreetAddr();
        void setCity(in string city);
        string getCity();
        void setCountry(in string country);
        string getCountry();
        void setEmail(in string email);
        string getEmail();
        void setPhone(in string phone);
        string getPhone();
        void setFax(in string fax);
        string getFax();
    };Here's the method I expect to be able to implement:  public Record[] getRecords()
        Record r = null;
        Record[] allRecs;
        int index = 0;
        String selectAll = "SELECT * FROM Record ORDER BY Record_number";
        try
          Statement s = connection.createStatement();
          ResultSet recs = s.executeQuery(selectAll);
          while(recs.next())
            index++;
          allRecs = new Record[index];
          //cycle through records again, adding each
          //to the array
          index = 0;
          recs = s.executeQuery(selectAll);
          while(recs.next())
            r = new Record();
            r.setRecordNumber(recs.getInt(1));
            r.setFirstName(recs.getString(2));
            r.setLastName(recs.getString(3));
            r.setStreetAddr(recs.getString(4));
            r.setCity(recs.getString(5));
            r.setCountry(recs.getString(6));
            r.setEmail(recs.getString(7));
            r.setPhone(recs.getString(8));
            r.setFax(recs.getString(9));
            allRecs[index] = r;
          catch (SQLException ex)
            exceptionCode(ex);
        return allRecs;
      }The compiler error lists the 9 sub-methods as "can't resolve symbol", because as the Record.java file generated by the idlj shows, the methods aren't there:package hw5Corba;
    * hw5Corba/Record.java
    * Generated by the IDL-to-Java compiler (portable), version "3.0"
    * from Record.idl
    * Tuesday, November 20, 2001 10:08:15 PM CST
    public final class Record implements org.omg.CORBA.portable.IDLEntity
      public int recordNumber = (int)0;
      public String firstName = null;
      public String lastName = null;
      public String streetAddress = null;
      public String city = null;
      public String country = null;
      public String phone = null;
      public String eMail = null;
      public String fax = null;
      public Record ()
      } // ctor
      public Record (int _recordNumber,
    String _firstName, String _lastName,
    String _streetAddress, String _city,
    String _country, String _phone,
    String _eMail, String _fax)
        recordNumber = _recordNumber;
        firstName = _firstName;
        lastName = _lastName;
        streetAddress = _streetAddress;
        city = _city;
        country = _country;
        phone = _phone;
        eMail = _eMail;
        fax = _fax;
      } // ctor
    } // class Record What do I need to do to implement these methods declared in the .idl file?

  • Why use an Abstract Class ?

    I am new to Java and for some reason I can't get my head around why to use an abstract class. I understand that an abstract class is something like:
    public abstract class Food{ // abstract class
    public void eat(){
    // stub
    public class Apple extends Food{
    public void eat(){
    // Eat an apple code
    }So basically the idea above is that you can eat an "apple" but you can't eat "food" because you can't instantiate an abstract class.
    I understand what an abstract class is and how to write one. What I don't understand is why you would use it? It looks to me like I could have just created a normal class called "Food" and just not instantiated it. What are the benefits of using an abstract class?

    807479 wrote:
    I am new to Java and for some reason I can't get my head around why to use an abstract class.One of the first books I ever read about Object-Oriented design contained the following quote from [url http://en.wikipedia.org/wiki/Lucius_Cary,_2nd_Viscount_Falkland]Lord Falkland:
    "When it is not necessary to make a decision, it is necessary +not+ to make a decision."
    It took me quite a while to understand, but it's all about flexibility: As soon as you cast something in stone, you lose the ability to change it later on if something better/more appropriate comes along. Interfaces and abstract classes are all about delaying that decision.
    As jverd said, interfaces allow you to specify what is required without defining the how; and as ErasP said, abstract classes are usually incomplete: ie, they define some of the 'how', but not all of it.
    What is most important about abstract classes though is that they cannot exist on their own: They must be extended by a concrete class that completes the 'how' before they can be instantiated and, as such, they declare the intent of the designer.
    One of the most important uses of abstract classes is as "skeleton implementations" of interfaces, and there are a lot of examples of these in the Java Collections hierarchy. My favourite is probably AbstractList, which contains a skeleton implementation of a List. Because it exists, I can create a class that wraps an array as a List with very little code, viz:public final class ArrayAsList<T>()
       extends AbstractList<T>
       private final T[] values;
       public ArrayAsList(T... values) {
          this.values = values;
       @Override
       public T get(int index) {
          return values[index];
       @Override
       public T set(int index, T element) {
          T value = get(index);
          values[index] = element;
          return value;
       @Override
       public int size() {
          return values.length;
    };and somewhere else, I can use it:   List<String> letters =
          new ArrayAsList<String>("a", "b", "c");or perhaps, more practically:   List<String> words = new ArrayAsList<String>(
          bigTextString.split(" +") );Now that may not seem like a big deal to you, but given all that Lists can do, it's actually a very powerful bit of code. The above example is from "Effective Java" (p.95).
    HIH
    Winston

  • Abstract class

    i know the concept of abstract class in java and this concept is used in interface, i.e all the methods declared in interface are abstract. i want to know how the abtract class is different from the normal class in java

    TinaV wrote:
    i know the concept of abstract class in java and this concept is used in interface, i.e all the methods declared in interface are abstract. i want to know how the abtract class is different from the normal class in java
    The only difference is that an abstract class can't be instantiated.
    Kaj

  • Abstract Class and polymorphism - class diagram

    Hi,
    ]Im trying to draw a class diagram for my overall system but im not too sure how to deal with classes derived from abstract classes. I'll explain my problem using the classic shape inheritance senario...
    myClass has a member of type Shape, but when the program is running shape gets instantiated to a circle, square or triangle for example -
    Shape s = new circle();
    since they are shapes. But at no stage is the class Shape instantiated.
    I then call things like s.Area();
    On my class diagram should there be any lines going from myClass directly to circle or triangle, or should a line just be joining myClass to Shape class?
    BTW - is s.Area() polymorphism?
    Thanks,
    Conor.

    Sorry, my drawing did not display very well.
    If you have MyClass, and it has a class variable of type Shape, and the class is responsible for creating MyClass, use Composition on your UML diagram to link Shape and MyClass.
    If you have MyClass, and it has a class variable of type Shape, and the class is created elsewhere, use Aggregation on your UML diagram to link Shape and MyClass.
    If you have MyClass, and it is used in method signatures, but it is not a class variable, use Depedency on your UML diagram to link Shape and MyClass. The arrow will point to Shape.
    Shape and instances of Circle, Triangle, Square, etc. will be linked using a Generalization on your UML diagram. The arrow will always point to Shape.
    Anything that is abstract (class, method, variable, etc.) should be italicized. Concrete items (same list) should be formatted normally.
    BTW, the distinction between Composition, Aggregation and Dependency will vary from project to project or class to class. It's a gray area. Just be consistent or follow whatever guidelines have been established.
    - Saish

  • Why use abstract classes?

    Why should I use abstract classes instead of a regular class with empty method bodies? Just better design? Is there some logical or performance based reason?

    Why should I use abstract classes instead of aregular
    class with empty method bodies? Just better design?Is
    there some logical or performance based reason?Because it describes what you're doing.
    If you define a "regular" class with empty message
    bodies, everyone who looks at it will say "WTF is he
    trying to do" or, if they're charitable, "Look,
    Harvey, someone who's trying to make Java look just
    like C++!".
    sigh Maybe answers like THIS are why people keep asking the same question.
    Here's a couple things an abstract class does that a "regular" class with empty methods bodies doesn't:
    1) An abstract class cannot be instantiated.
    2) An abstract class forces it's abstract methods to be implemented.
    If you were to extend a non-abstract class with empty method bodies, you wouldn't have to override the methods... you could just leave them empty. An abstract class forces it.
    There's a lot more reasons... those are a couple obvious ones.

  • Abstract Class & Interfaces

    Can anyone please tell me as to why we need both an abstract class & an interface? I was asked in an interview as to why we need 2 separate concepts when we can get the similar functionality of an interface by using an abstract class. I had just sited their differences like:
    1) An abstract class can have both abstract & normal methods & that we can specify different access specifiers for its class members.
    2) ABAP does not support Multiple inheritance but that we could simulate the same using interfaces concept in ABAP.
    But he wasnt satisfied with the answer. I guess he was expecting something from a practical point of view. I did try searching the old threads but there wasnt anything similar to this. Anyone please explain by citing a scenario as to why we would need 2 separate concepts & not just one .
    Thanks in advance

    Hi
    Abstract classes
    Abstract classes are normally used as an incomplete blueprint for concrete (that is, non-abstract) subclasses, for example to define a uniform interface.
    Classes with at least one abstract method are themselves abstract.
    Static methods and constructors cannot be abstract.
    You can specify the class of the instance to be created explicitly: CREATE OBJECT <RefToAbstractClass> TYPE <NonAbstractSubclassName>.
    Abstarct classes themselves can’t be instantiated ( althrough their subclasses can)
    Reference to abstract classes can refer to instance of subclass
    Abstract (instance) methods are difined in the class , but not implemented
    They must be redefined in subclasses
    CLASS LC1 DEFINAITION ABSTARCT
    PUBLIC SECTION
    METHODS ESTIMATE ABSTARCT IMPORTING…
    ENDCLASS.
    <b>Interfaces</b>
    Interfaces only describe the external point of contact of a class (protocols), they do not contain any implementation.
    Interfaces are usually defined by a user. The user describes in the interface which services (technical and semantic) it needs in order to carry out a task.
    The user never actually knows the providers of these services, but communicates with them through the interface.
    In this way the user is protected from actual implementations and can work in the same way with different classes/objects, as long as they provide the services required. This is known as polymorphism with interfaces.

  • When should I use abstract classes and when should I use interfaces?

    Can any body tell me in which scenario we use /we go for Interface and which scenario we go for abstract class, because as per my knowledge what ever thing we can do by using Interface that thing can also done through abstract class i mean to say that the
    behavior of the two class.
    And other thing i also want to know that which concept comes first into the programming abstract class or Interface.
    S.K Nayak

    The main differences between an abstract class and an interface:
    Abstract
    An abstract class can contain actual working code (default functionality), and can have either virtual or abstract method.
    An abstract class must be sub-classed and only the sub-classes can be instantiated. Abstract methods must be implemented in the sub-class. Virtual methods may be overridden in the sub-class (although virtual methods typically contain code, you still may
    need/want to override them). A good use for an abstract class is if you want to implement the majority of the functionality that a class will need, but individual sub-classes may need slightly different additional functioality.
    Interface
    An interface only contains the method signatures (method name and parameters), there is no code and it is not a class.
    An interface must be implemented by a class. An interface is not a class and so it cannot be sub-classed. It can only be implemented by a class. When a class implements an interface, it must have code in it for each method in the interface's definition.
    I have a blog post about interfaces:
    http://geek-goddess-bonnie.blogspot.com/2010/06/program-to-interface.html
    (sorry, I have no blog posts specific to abstract classes)
    ~~Bonnie DeWitt [C# MVP]
    http://geek-goddess-bonnie.blogspot.com

  • Abstract class methods

    I'm confused. Is this true or false.
    The great thing about polymorphism is that you can call one method. If the subclass inherited that method, it will be customized and perform a different duty. That way, the action it performs will depend on 1>whether or not it's a sub or super class and also 2>if the method was overridden if it was a subclass.
    Now, my confusion. If an object reference is to a Super-abstract-class... how do the method calls and properties go?? well let me let you answer for me. Thanks so much in advance for this clarification.

    Yes. You are - pretty much.
    The abstract class, as such, can never be instantiated. BUT a class derived from the superclass IS an instance of the superclass.
    Silly example:
    abstract public class Animal {
       public Animal() {
       public abstract int getNumberOfLegs();
    }That's our animal class, and we know that anything that's an animal has a number of legs - but we can't just create a "generic" animal.
    public class Cat extends Animal {
       public Cat() {
          super();
       public int getNumberOfLegs() {
          return legCount;
       public void maim(int legsToRemove) {
          legCount -= legsToRemove;
          if(legCount < 0 ) legCount = 0;
       private int legCount = 4;
    }A Cat is a specific type of animal, so we can find out how many legs it has (usually 4). Note again that a cat IS an animal, so Cat IS an instance of Animal.
    Java even provides a special operator to test this:
    Cat cat = new Cat();
    System.out.println("A cat is a cat: " + (cat instanceof Cat));
    System.out.println("A cat is an animal: " + (cat instanceof Animal));The term used to describe the "Guarantee" that a subclass of an abstract class (or an implementation of an interface) is usually and technically a "contract", but I prefer to think of it as a "Promise" since you can break the promise by messing with the bytecode - at which point the JVM will spot the lie and complain !
    D.

  • Abstract class method polymorphically using constructors?

    how can i have a method defined in an abstract superclass call a constructor of the actual class running the method?
    abstract class A {
    public List getMultple() {
    List l = new ArrayList();
    for (short i=0;i<4;i++) {
    l.add(this());//<obviously this breaks
    return l
    or something like that. A won't run this method, but its children will...and they can call their constructors, but what do i put here to do that?
    i've tried a call back. an abstract method getOne() in the superclass forces each child to define that method and in each of those i return the results of a constructor. that works fine.
    the problem is i want to abstract this method out of each of these children classes cause its the exact same in each one, just using a different constructor to get multiple of each in a list. so if i use this callback method, then i am not saving the number of methods in each class, so why bother at all?
    any ideas?

    I still say you are coming at it from the wrong angle. A super class is not the way to go. What you are doing sounds like something very similar to something I did not too long ago.
    My requirement was that I had tab delimited text files filed with data that I had to parse. Each line would be used to instantiate one object, so a particular file could be used to instantiate, for example, a thousand objects of the same class. There were different types of files corresponding to different classes to instantiate instances of.
    Here is the design I ended up using.
    An object of class DataTextFileReader is instantiated to parse the text file and generate objects. It includes code for going line by line, handling bad lines and generating objects and reports. The constructor:
    public DataTextFileReader(File inputFile, LineParser<T> theLineParser)LineParser is an interface with one method:
    public T read(String line);When you call a load() method of the DataTextFileReader, it does its thing with the aid of the LineParser's read method, to which each line is passed, and stores the generated objects in an ArrayList. This can be returned by using another method. There are other methods for getting the reports, etc.
    Obviously, the LineParser chosen needs to have code appropriate for parsing the lines in question, so you have to choose and instantiate the right one.
    I find this design to work well. I arrived at it after spending hours giving myself headaches trying to come up with a design where there was a superclass roughly equivalent to the DataTextFileReader mentioned above, and classes extending this that fulfilled the duty of the LineParsers mentioned above... rather like what you are trying to do now.
    I did not care for the solution at first because it did not give me the "Ah, I am clever!" sensation I was expecting when I finally cracked the problem using inheritance, but I quickly came to think that it was much better OOD anyway.
    The LineParsers mentioned above are essentially embodiments of the Factory pattern, and I would recommend you do something similar in your case. Obviously your "constructors" all have to be different, so you should make a separate class for each of those. Then you can put the code that performs the query and loops to create loads of objects in another class called something like DatabaseDepopulator, using appropriate generics as in my example. Really it is the same problem, now that I look at it.
    This will also result in better separation of concepts, if you ask me. Why should the class constructor know how to parse a database result query, much less perform the query? It has nothing to do with databases (I presume). That is the job of an interpreter object.
    As a final note, remember... 95% of the time you feel like the language won't let you do what you want, it is because you shouldn't anyway.
    Drake

Maybe you are looking for