• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Source code file naming w/ access modifiers  RSS feed

 
Winston Liek
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is this not valid in java:
Both uses public with the same class/interface name.

Test.java:

public class Test implements Test{
/// Some codes
}

public interface Test{
///Some methods
}
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37465
539
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see two problems. One is that you are only allowed to have one public class/interface in a single physical file.

The other is that you have two classes named Test. (And interface compiles to a class). Java can't compile this because they will both wind up with the same name Test.class.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just out of curiosity...what happened when you tried compiling it? That would be a pretty easy way to see if it is legal or not...
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!