• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

import classes.<className> statement does not compile

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am studying for the Sun Certified Programmer Java 2 (CA-WGS-PREX-J055C)‏ Certification Exam, scheduled for MO November 30.
I purchased the three ePractice exams directly from Sun.
***************************************************************
One question is as follows:

Given two files:



And:



When class StaticStuff has been compiled, what is the result when you attempt to compile class FindStatic?
***************************************************************
The file FindStatic.java is in my current directory, and I created a subdirectory called 'x' with the file StaticStuff.java.

The compilation error message is:
FindStatic.java:9: cannot find symbol
symbol : class StaticStuff
location: class FindStatic
ss = new StaticStuff();
^

If I comment out the offending line, compilation is successful. Hence I know that my directory structure is correct.

The answer from Sun says:
Adding the line 'import classes.StaticStuff;' will allow this line to compile.

I did this and the code still failed compilation:
FindStatic.java:2: package classes does not exist
import classes.StaticStuff;
^
FindStatic.java:9: cannot find symbol
symbol : class StaticStuff
location: class FindStatic
ss = new StaticStuff();
^

I'm assuming that there is a typo in the answer. I sent an e-mail to Sun two weeks ago but have not gotten a response yet.

Thank you for your help,
Bonnie Thanh
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


They probably forgot to declare ss. Should be



Or declare a member variable and assign that to new StaticStuff();
 
Sheriff
Posts: 9680
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bon, welcome to javaranch!

Please Use Code Tags when you post a source code. You can edit your message using button and then add code tags to it...
 
Bon Thanh
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ankit, code tags are noted.

Hi Deepak,

I tried your suggestion:
StaticStuff ss = new StaticStuff();

And am still getting compilation errors:

FindStatic.java:2: package classes does not exist
import classes.StaticStuff;
^
FindStatic.java:9: cannot find symbol
symbol : class StaticStuff
location: class FindStatic
StaticStuff ss = new StaticStuff();
^
FindStatic.java:9: cannot find symbol
symbol : class StaticStuff
location: class FindStatic
StaticStuff ss = new StaticStuff();
^

I thought that perhaps they had meant to use the Class object representing the StaticStuff class - StaticStuff.class. But that did not work either.

Bonnie
 
Ankit Garg
Sheriff
Posts: 9680
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bon, you don't need to change the line ss = new StaticStuff(); as the ss will be available due to the static import. The error doesn't say that unknown symbol ss, it says unknown symbox StaticStuff. First of all don't import classes.StaticStuff instead use two import statements

If you don't include the second import, it won't be able to find the class StaticStuff. If you don't want to use the second import, then you'll need to change the line ss = new StaticStuff(); to ss = new x.StaticStuff(); ...
 
Bon Thanh
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit,

Your solution works! And your explanation does make sense. The compiler did NOT indeed complain about the variable ss, because it is recognized by the import x.StaticStuff.* statement. It is complaining about the StaticStuff class itself.

I wish Sun Microsystems would be more responsible for the errata in their very own ePractice exams.

Thanks to both you and Deepak for making my first experience at JavaRanch a very rewarding and pleasant one.
Bonnie
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bon, you don't need to change the line ss = new StaticStuff(); as the ss will be available due to the static import.



I failed to see that ss was a variable in the class. Aaargh ! thanks for the correction.

oh a new member. Welcome to java ranch
 
Ankit Garg
Sheriff
Posts: 9680
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Bala wrote:I failed to see that ss was a variable in the class. Aaargh !


Even I couldn't see it till the code was formatted using the [code][/code] tags. This is the benefit of using code tags ...
 
reply
    Bookmark Topic Watch Topic
  • New Topic