I was reading the K&B book and interfaces are said to be implicitly abstract. They can also have two access levels: public and default. My first question is:
Is it correct that interfaces cannot be private or protected?
Secondly, because I see that interfaces can have package access level, does that mean that interfaces can belong to a particular package? So we can add statement to an interface file?
If the answer is yes, interfaces can belong to a package then can we use when an interface wants to extend another interface.
Hopefully the questions are clear and will make sense.
There is one extra thing you may be interested to know, which is that an interface can be nested within a class, and in that case it can be declared protected or private. But I do not know whether this is necessary to know for the exam.
Dennis Deems wrote:The answer to all your questions is yes.
There is one extra thing you may be interested to know, which is that an interface can be nested within a class, and in that case it can be declared protected or private. But I do not know whether this is necessary to know for the exam.
Thanks. I haven't yet come across interfaces nested inside a class. Fingers crossed.
A nested interface is any interface whose declaration occurs within the body of another class or interface. A top-level interface is an interface that is not a nested interface.
You told a very interested point 'nested interface can be private or protected in a class' and i want to what the purpose of it???
I have never found any use for it in my own code, and no one has been able to show me an example that seemed useful. It's just one of those things the language allows us to do. :/
Dennis Deems wrote:But I do not know whether this is necessary to know for the exam.
Hello Dennis...Hello Ranchers
I guess it is necessary to know that interfaces can be nested for the purpose of the exams. They can even be declared within enums!
Its one of the many TRIP-TRAPS you may find in the exams.
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
And then the entire population worshiped me like unto a god. Well, me and this tiny ad:
a bit of art, as a gift, that will fit in a stocking