Marcelo Vieira

Greenhorn
+ Follow
since Jul 13, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Marcelo Vieira

Well, I "kind of" figured out why the class B was not compiled. While studying I've created and compiled many A.java files (of course, in the same path). For some reason, the A.class file wasn't being updated whenever I compiled it. I just had to exclude the .class file and I became able to compile it again. But the most important thing is that I could see how does the default access works!

Regards
14 years ago
Thank you all for the help, but it doesn't compile. I've excluded the directory structure so that now I don't have any packages, ie., both files (A.java and B.java) are in my root directory, without any "src" or "bin" directories, and I also don't have any constraints about the class path, onde the root directory in my system path. However, even this structure didn't let me compile the B.java file. I'm still getting the same error: the compiler could not find the C class.

I'l try to figure out what is happening and when I get it I'll post here, for anyone interested.

Regards.
14 years ago

Tom Reilly wrote:The default class modifier allows a class to be used (i.e. new C()) from any other class within the same package. It does not, however, allow classes within the same package to extend the class. You must set the class modifier to protected or public to do that.



Hello Tom, thanks for the quickly response.

If I'm not wrong, a class cannot have a protected modifier. I've tried to instantiate a variable of type C instead of extending the C class (the code is shown below), but I still get the same error. The compiler still can't find the class C.



I've tried, just for curiosity, to extend and instantiate the A class (wich is public) and it worked with no problems, as we would expect.

Any ideas?

Thank you
14 years ago
Hello everyone,

I just started studying java and I found one thing that is making me a bit confused. Please, consider the following code:




My intention with the above code was to understand how does the default access to a class works (and a class member). As I could understand, once the classes are in the same package, it is possible to use the class C (in the file A.java) in the code of class B (in the file B.java). However, I'm getting the following error after trying to compile B:

C:<my path>\src>javac -d ../bin test/B.java
test\B.java:5: cannot find symbol
symbol: class C
public class B extends C{
^
1 error

The directory structure is as follows:

/root
--------/src
-------------/test
------------------A.java
------------------B.java
------- /bin
------------/test
-----------------A.class


Does anybody have any idea about why I can't access the C in the class B, even both belonging to the same package?

Thank you very much.
14 years ago