-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 ..!!

2

3 Answers 3

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?

Sign up to request clarification or add additional context in comments.

Comments

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).

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.