GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes default access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "default access" Watch "default access" New topic
Author

default access

pradeepta chopra
Ranch Hand

Joined: Jul 05, 2008
Posts: 137
default.java file


---------------------------------------
testdefault.java file


[B]
[/B]
----------------------------------------------
when i complie testdefault.java
it gives an error stating that cannot find Smclass

but default access is package level access and Smclass should be accessible by othrclass
take a look
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
Are these the errors you're getting when you compile?

nathans-macbook-pro: pack Nathan$ javac othrclass.java
othrclass.java:15: class testdefault is public, should be declared in a file named testdefault.java
public class testdefault{
^
othrclass.java:7: cannot find symbol
symbol: class Smclass
class othrclass extends Smclass{
^
othrclass.java:10: cannot find symbol
symbol : class Smclass
location: class pack.othrclass
Smclass s=new Smclass();
^
othrclass.java:10: cannot find symbol
symbol : class Smclass
location: class pack.othrclass
Smclass s=new Smclass();
^
4 errors


Or is this the error you're getting?

nathans-macbook-pro: pack Nathan$ javac othrclass.java Smclass.java
othrclass.java:15: class testdefault is public, should be declared in a file named testdefault.java
public class testdefault{
^
1 error


[ July 21, 2008: Message edited by: Nathan Leniz ]

The very existence of flamethrowers proves that at some time, some where, some place, someone once said to themselves "I'd really like to set those people on fire over there, but I just can't get close enough".
pradeepta chopra
Ranch Hand

Joined: Jul 05, 2008
Posts: 137
yes i am getting the same errors as your 4 errors leaving your 1st error because the file is saved as testdefault.java
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
So you have two files, one named testdefault.java and the other named Smclass.java, but you're only compiling testdefault.java. This would create a testdefault.class but Smclass.class doesn't exist.
pradeepta chopra
Ranch Hand

Joined: Jul 05, 2008
Posts: 137
yes i was making the mistake pointed out by you but even if i compile both files named default.java and testdefault.java
i still get the same 3 errors that you got.
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
Try removing public from your Smclass declaration and see what happens.

Edit -- Sorry, I didn't see that you had saved Smclass in default.java
[ July 21, 2008: Message edited by: Nathan Leniz ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39103
    
  23
Those errors don't match what you said in your original post.

SmClass won't compile because it is public so it ought to be in a file called SmClass.java. You need to change its name to SmClass.java, then compile that file first. Leave the public declaration unchanged.

You can get no end of confusion, and misleading answers, if you don't Post Real Code, and real errors.
[ July 21, 2008: Message edited by: Campbell Ritchie ]
pradeepta chopra
Ranch Hand

Joined: Jul 05, 2008
Posts: 137
even if i remove public modifier or i save it as Smclass.java when i keep public then also i m getting the above three errors
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
Are you compiling both classes at the same time? i.e.
[B][/B]

Imagine you're making a salad, and the recipe says you need lettuce, carrots, cucumbers, feta cheese, bacon bits, croutons, and ranch dressing. The name of this salad is called "The JavaRanch Mix". So you put all the ingredients minus the croutons in a pile.

Now, you don't actually have the the croutons made, but you have a recipe for them and all the ingredients to make them.

Think of javac like a super smart kitchen appliance. Your java files are the recipes and they contain the ingredients too. If you feed javacl the recipe and the ingredients for "The JavaRanch Mix" it will fail, because your croutons aren't made. But if you give it the recipe and ingredients for both the salad and the croutons, it's smart enough to know it has to make the croutons first, then it'll mix all the ingredients together and make what you want.

EDIT--
If you are compiling both, then try navigating up one directory and type


I don't know why, but when I'm working with classes in packages I always have to go up a directory.
[ July 21, 2008: Message edited by: Nathan Leniz ]
 
GeeCON Prague 2014
 
subject: default access