Accessibility Example from Khalid Mughal-getting compilation errors
Esther Kak
Ranch Hand
Joined: Oct 11, 2006
Posts: 51
posted
0
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
posted
0
Can somebody explain why this is not compiling?
dhwani mathur
Ranch Hand
Joined: May 08, 2007
Posts: 621
posted
0
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...............
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
posted
0
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
posted
0
Could anybody please reply on this!!! Thanks in Advance
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).