is it good "form" to declare new classes in the same file ?

Posted by hatorade on Stack Overflow See other posts from Stack Overflow or by hatorade
Published on 2009-09-02T09:45:47Z Indexed on 2010/04/04 16:13 UTC
Read the original article Hit count: 112

Filed under:
|
|
|

I code in Python a lot, and I frequently create classes. Now, I'm not sure if this is good Python form, but I just declare a class in the same file as my main().

class foo {
...
}

I'm wondering if it's good form in Java to do the same?

For example,

class foo {
    public static int name;
    public static int numPoints;
    public static int[] points;
}

public class bar {

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

Does not throw errors in Eclipse, so it must be allowed. But is it okay to do? Would it be better to just declare this class in a separate file..?

Edit: I just want to emphasize that my new class literally is just a container to hold the same type of data multiple times, and literally will only have like 3 values. So it's total about 5 lines of code. The question is - does this merit a new file?

© Stack Overflow or respective owner

Related posts about java

Related posts about classes