• Post Reply Bookmark Topic Watch Topic
  • New Topic

Some basic questions , i dont know the answer for  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Why only one public class is allowed in a java file, it shudnt matter as a separate class file is created for each class???

2. Why different name is allowed for the java file for an interface, though the interface name is different and class file is created as per interface name

Can anyone answer this please
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#1 is a convention to make life easier for the compiler. If you tell it to compile class A and it finds a reference to B it needs to find out if B is up to date. To do that it has to find the souce and class files for B. Putting the source for B in a file called B makes this easy. If you could put any number of public classes in one file, B could be in any file in the package and it would be harder to find.

#2 I'm not following ... the filename has to match the Interface name, just like a Class, right?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!