Reputation: 301
Is it possible to define an interface like this:
public interface Test{
public string name1;
private String email;
protected pass;
}
Upvotes: 8
Views: 17694
Reputation: 181
being java
only public, static & final are permitted
You should use an abstract
class instead of an interface
if you want to declare its fields.
Upvotes: 4
Reputation: 7147
Having private or protected members in an interface doesn't make sense conceptually. By definition something that is "private" isn't exposed and therefore, anyone consuming the interface would not care if the implementing class had a private email field or not.
Only public members matter to the code consuming the interface.
Upvotes: 5