aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Accessibility Example from Khalid Mughal-getting compilation errors 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 "Accessibility Example from Khalid Mughal-getting compilation errors" Watch "Accessibility Example from Khalid Mughal-getting compilation errors" New topic
Author

Accessibility Example from Khalid Mughal-getting compilation errors

Esther Kak
Ranch Hand

Joined: Oct 11, 2006
Posts: 51
I am trying to work on example 4.8(Pg No:116) but I could'nt compile





Compilation Errors are below

symbol : class SuperClassA
location: class Ekak.MyFavorites.Certification.KhalidMughal.PackageA.SubClassA
class SubClassA extends SuperClassA{
^
C:\Ekak\My Favorites\Certification\KhalidMughal\PackageA\SubClassA.java:5: cannot resolve symbol
symbol : variable superClassVarA
location: class Ekak.MyFavorites.Certification.KhalidMughal.PackageA.SubClassA
superClassVarA = 10;
^
C:\Ekak\My Favorites\Certification\KhalidMughal\PackageA\SubClassA.java:6: cannot resolve symbol
symbol : variable superClassVarA
location: class Ekak.MyFavorites.Certification.KhalidMughal.PackageA.SubClassA
System.out.println("superClassVarA from subclass:"+superClassVarA);
^
3 errors
Esther Kak
Ranch Hand

Joined: Oct 11, 2006
Posts: 51
Can somebody explain why this is not compiling?
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
Hi


i think the variable in the super class must be declared as
protected.............

so try the below code








try the above code and
do let me know if it works...............
Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

The syntax of the original code is fine. It compiles fine, no problem there.
No need to add protected or anything (read your K&B).

The reason this does not work is because you compile it wrong. you probably type in the javac instruction yourself, and your classpath is wrong.

please post the javac line.

grtz
mark


I know where my towel is. (SCJP 5, OCPJWCD)
[Free Quiz Tips for a fun night with friends or family] Flash games
Mohit Jain
Ranch Hand

Joined: Jun 04, 2007
Posts: 74
Use the compilation statement -

>javac -d . SuperClassA.java SubClassA.java

It creates the package directories automatically and compiles the code fine.


SCJP 5.0, SCWCD in progress
Esther Kak
Ranch Hand

Joined: Oct 11, 2006
Posts: 51
Hi Mohit Jain,
I tried but it did not work with your compilation statement javac -d . SuperClassA.java SubClassA.java

PATH VARIABLE is
C:\j2sdk1.4.2_12\bin

CLASSPATH VARIABLE is
C:\Ekak\My Favorites\Certification\KhalidMughal
Both the following programs are in PackageA under khalidMughal directory.
Program1-SuperClassA.java
Accessibility is:
  • Class name - is default
  • Class variable - public
  • Class method - public

  • Program2 - SubClassA.java
    SubClassA.java extends SuperClassA.java which is in the same package. And defines a simple method to access the superclass variable.

    But the error I get is cannot resolve symbol: SuperClassA
    I have the path variable set to point to the bin dir
    I have my classpath variable set to point to KhalidMughal but not packageA

    Why am I not able to compile the code. Need Help. Can anyone explain?
    Esther Kak
    Ranch Hand

    Joined: Oct 11, 2006
    Posts: 51
    Could anybody please reply on this!!! Thanks in Advance
    Mark Uppeteer
    Ranch Hand

    Joined: Mar 02, 2004
    Posts: 159

    hi Esther Kak ,

    I 'managed' to reproduce your error because it always just seem to compile fine for me.
    I get your error, when I execute compilation of the subclass without the superclass being on the same compilation line.

    Position yourself in the folder of your java files.
    javac SubClassA.java gives me:
    ----
    SubClassA.java:2: cannot find symbol
    symbol: class SuperClassA
    class SubClassA extends SuperClassA
    ^
    SubClassA.java:5: cannot find symbol
    symbol : variable superClassVarA
    location: class Ekak.MyFavorites.Certification.KhalidMughal.PackageA.SubClassA
    superClassVarA = 10;
    ^
    SubClassA.java:6: cannot find symbol
    symbol : variable superClassVarA
    location: class Ekak.MyFavorites.Certification.KhalidMughal.PackageA.SubClassA
    System.out.println("superClassVarA from subclass:"+superClassVarA);
    ^
    3 errors

    ----

    but when I execute

    javac SubClassA.java SuperClassA.java

    everything compiles just fine.
    This error occurs because you try to compile a class (SubClassA) that needs a superclass (SuperClassA) but SuperClassA.class doesn't exist yet (or isn't found).
    Mark Uppeteer
    Ranch Hand

    Joined: Mar 02, 2004
    Posts: 159

    now I see its even not the same error. yours is 'resolve', mine is 'find'.
    Guess I didn't manage to reproduce your error after all.

    Fact is that there is nothing wrong with the code. Its configuration.
    Esther Kak
    Ranch Hand

    Joined: Oct 11, 2006
    Posts: 51
    Thankyou for taking time to reproduce errors and solve it. Your answer helped me.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Accessibility Example from Khalid Mughal-getting compilation errors