-2

Possible Duplicate:
Java: Multiple class declarations in one file

Recently I was going through a java class in which I have discovered that it was a java class with the named A but after that there was another class named B was written after Class A in the same java file ..like this

class A
{


} 

Class B
{

}

but the class was finally saved with the name A.java , Please let me know is it any kind of design pattern ..!!

Community
  • 1
  • 1
user1614879
  • 43
  • 1
  • 5
  • 1
    It is not really a design pattern. Just something author decided to do. This is not usually done in practice. – jn1kk Aug 23 '12 at 17:33
  • 1
    Looks like it has already been discussed here [http://stackoverflow.com/questions/2336692/java-multiple-class-declarations-in-one-file][1] [1]: http://stackoverflow.com/questions/2336692/java-multiple-class-declarations-in-one-file – Davz Aug 23 '12 at 17:34

3 Answers3

7

Not a design pattern.

You can have more than 1 java class written in a single file but the name of the file should be the same name as the public class in the file.

Why are filenames in Java the same as the class name?

Community
  • 1
  • 1
Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
2

At most one public class is allowed in a java file and file name must match with the name of public class (if there is any).

I am not aware of any design pattern that uses this technique (or rather flexibility).

Amresh
  • 478
  • 1
  • 6
  • 28
0

There is no design pattern here. Due to the fact that there was no public class declaration, the one file could be called either A.java or B.java.

Reimeus
  • 158,255
  • 15
  • 216
  • 276