aspose file tools*
The moose likes Beginning Java and the fly likes visibility Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "visibility" Watch "visibility" New topic
Author

visibility

Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
In a folder called "kathy" on my "desktop", I creates a file called "chapter1exercise1" I am using Textpad and compile the code using the Textpad > Tools




A sub-folder is created inside "kathy" folder called "new1". The following file "another" is created inside this folder "new1"



I am messing up with package declaration here but cannot figure out how. Any clues ?

Compile error



Regards,<br />Arnab
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
chapter1exercise1 is a public class.. why is it not visible ?
Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
Dear Readers,
What might be the problem is that the kathy package is not set into the classpath variable. Just try using the DOS Window and while compiling set the classpath to the kathy package.


With Best Regards,
Shyam Prasad Murarka
Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
Dear Readers,
OK, Arnb.. Here's what I did. I made a few changes here and there to get the following results:


In the above code I changed the scope of the test() method from the default scope("friendly") to public. This was done so that the abc() method of another class had the visibility to see this method.




In the above code, I made the class public so that it could be accessible to another class "test". This was done only for testing purposes.
I added a constructor so that the abc() method could be called for testing purposes.



The above class was made for testing purposes only.

Now the structure of file directory is like this:
kathy>>new1>>another.java
kathy>>chapter1exercise1.java
kathy>>test.java

Now in the command line of DOS Window I first navigated inside the kathy folder.
G:\kathy>javac -cp .;.. test.java

G:\kathy>java -cp .;.. test

And the Output was as expected:
in test

NOTE: in "-cp" --- "." refers to current directory
and ".." refers to parent directory
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
hmm.. so it was more of class path issue ??

But even without changing the access modifiers, will it work when compiled from DOS prompt ? I will try it out!
Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
Dear Arnb,
Like I told you before you will have to change the access modifier of test() method to public because the default modifier does NOT allow access the package. The other changes are not necessary.
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
Hi Shyam,

That is correct.

I compiled it from dos prompt with the following command when I was in the folder "new1"



and that clears my doubt !
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Now that you're getting the hang of things, see if THIS helps.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
zhu pan
Greenhorn

Joined: Dec 25, 2005
Posts: 4
code:
--------------------------------------------------------------------------------

package kathy;public class chapter1exercise1 { public static void main(String args[]) { System.out.println("in main"); } public void test() { System.out.println("in test"); }}

--------------------------------------------------------------------------------




A sub-folder is created inside "kathy" folder called "new1". The following file "another" is created inside this folder "new1"


code:
--------------------------------------------------------------------------------

package kathy.new1; import kathy.*; class another extends chapter1exercise1 { void abc() { test(); }}

--------------------------------------------------------------------------------
[ December 25, 2005: Message edited by: Marilyn de Queiroz ]

<a href="http://ctguzhupan.go1.icpcn.com/" target="_blank" rel="nofollow">http://ctguzhupan.go1.icpcn.com/</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: visibility