this code should not compile, right? Because I think import statement must come after package statement, and cannot be in the middle of the codes. (Correct me if I were wrong) But the answer given is producing output 8.
Solve this code:<br /> <br />10010101100001111011011000010100000111001011011111100011110101111100110100001
if you have such code, it is often the case that you have to put the classes in different files. If you do it right (may the package statements be with you), the code will compile and produce the output 8.
Hello, I didn't try to compile this code but I would say it will fail because x2 is protected and you can't have access to it through a reference but only through inheritance. (I suppose the 2 classes exist in two differents files)
Hi All, I got the answer. If the variable is a static protected one it can be accessed through dor operator in another package. If it is a protected one without static modifier, it can be accessed only thr inheritance in another package.
Given in K&B - Chap 2 "when a subclass-outside-the-package inherits a protected member, the member is essentially private inside the subclass, such that only the subclass and its subclasses(both in the same and different package)can access it."