V
V
vrazbros2016-09-12 13:43:54
OOP
vrazbros, 2016-09-12 13:43:54

Why can't you use protected or private in an interface?

Why can't protected or private be used in an interface? In an abstract class, you can...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fat Lorrie, 2016-09-12
@Free_ze

The interface is intended for declaring an external API without specifying the implementation. It should only have public members.
Generally speaking, this is an artificial limitation adopted for convenience. In the same C++, purely virtual (abstract) stateless classes are used as interfaces. The presence of a special syntactic construction (interfaces, as in C# or Java) makes it possible to clearly emphasize that there is no surprise for the programmer and this type is used as a "glue" between other classes.

R
res2001, 2016-09-12
@res2001

You can also use protected, then it will also be an interface for child classes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question