aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is default level class access really package level access? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is default level class access really package level access?" Watch "Is default level class access really package level access?" New topic
Author

Is default level class access really package level access?

Andrew Luo
Greenhorn

Joined: Mar 16, 2011
Posts: 5
In the chapter 1 page 13,
" Think of default access as package-level access, because a class with default access can be seen only by classes within the same package..."

But when I do the following in a "woo" dir:

file A.java

file B.java

I got:
cannot find symbol
symbol: class A

for the "A a = new A();" statement

How come foo of B could not access the default level (or package level) access class A? If I remove "package woo;" from both files, B.java compiles.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

You have to import the package where the class is located.


Mohamed Sanaulla | My Blog
Andrew Luo
Greenhorn

Joined: Mar 16, 2011
Posts: 5
They are in the same package. Why do I have to import? The "import woo.*" doesn't work for either file.
Suhas Mandrawadkar
Ranch Hand

Joined: Jul 21, 2007
Posts: 72

trying the above with

In file B.java.
Also B extends A.

Interesting. Its not working for me either. Just started preparing.


Regards, Suhas S. Mandrawadkar.
Certifications: SCJP 6, SCWCD 5, Oracle WebLogic Server Administrator, OCE Java EE 6 EJB Developer
Suhas Mandrawadkar
Ranch Hand

Joined: Jul 21, 2007
Posts: 72

Ahh,,worked ! The parent folder of the Woo directory must be in CLASSPATH
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

suhas mandrawadkar wrote:Ahh,,worked ! The parent folder of the Woo directory must be in CLASSPATH


Didnt notice that they were in same package.
Suhas Mandrawadkar
Ranch Hand

Joined: Jul 21, 2007
Posts: 72

But I m not able to access a public method in A using dot operator from B
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

suhas mandrawadkar wrote:But I m not able to access a public method in A using dot operator from B


Please post the code.
Suhas Mandrawadkar
Ranch Hand

Joined: Jul 21, 2007
Posts: 72





Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

The code you have posted has other compiler issues as well So please post a working code.
Suhas Mandrawadkar
Ranch Hand

Joined: Jul 21, 2007
Posts: 72

That is the code that you asked for What other compiler issues ?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

suhas mandrawadkar wrote:That is the code that you asked for What other compiler issues ?


Did you try to compile it?
Suhas Mandrawadkar
Ranch Hand

Joined: Jul 21, 2007
Posts: 72

yes.. compiles fine without
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 440

@ Suhas
your class A does not have any method
did you try to compile that code?

SCJP 6 [86%] June 30th, 2010
OCPWCD [84%] March 26th, 2012
OCEJPAD [83%] September 6th, 2014
If you find any post useful, click the "plus one" sign on the right
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

suhas mandrawadkar wrote:yes.. compiles fine without


And you didn't mention what is the compiler error
Suhas Mandrawadkar
Ranch Hand

Joined: Jul 21, 2007
Posts: 72

Mohamed Sanaulla wrote:
suhas mandrawadkar wrote:yes.. compiles fine without


And you didn't mention what is the compiler error


B.java:7: cannot find symbol
symbol : method eat()
location: class woo.A
a.eat();
^
1 error

Prasad Kharkar wrote:@ Suhas
your class A does not have any method
did you try to compile that code?



Huh ?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

You are forgetting something in the method declaration for eat
Suhas Mandrawadkar
Ranch Hand

Joined: Jul 21, 2007
Posts: 72

Mohamed Sanaulla wrote:You are forgetting something in the method declaration for eat


Now ?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

I could compile it fine

And please when you edit your older posts- do add a note that you fixed the code. Readers of this thread will be misguided.
Suhas Mandrawadkar
Ranch Hand

Joined: Jul 21, 2007
Posts: 72

Mohamed Sanaulla wrote:I could compile it fine

And please when you edit your older posts- do add a note that you fixed the code. Readers of this thread will be misguided.


aye aye Captain .. ! Will keep that in mind from now on
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is default level class access really package level access?