design application that can create instances of class while running

45 Views Asked by At

I am trying to figure out how to write an application for which I can create instances of a class(object) during the runtime of the application.

Sorry if this is a simple thing but i am still very new to OO and having trouble grasping this specific bit.

Below is some of the code that i would be using.

public class Task
{
    private String tskname;

    public task(String inTskName)
    {
        tskname = inTskName;
    }
}

In another class I would have my main

public class Application
{
    public static void main(String[] args)
    {
    }
}

So I understand that if i wanted to create an instance (knowing that it needed to be particular quantity or particular information, i would put the following in my main and then continue on with the rest of the code.

Task task1 = new Task();

I want to be able to create tasks while the application is running. how can I do this? I don't know how many tasks there will be. How do i allow for unlimited tasks? Would using an array as my variable in main be the correct way of handling this?

1

There are 1 best solutions below

0
On BEST ANSWER

How do i allow for unlimited tasks

It seems like you just want a way of storing the tasks? In that case just use a List

List<Task> tasks = new ArrayList<Task>();
tasks.add(new Task());