I have compiled this program and it created a class file in the same folder.
I created another program in the folder c:\javatest
The second program gives compilation error:
cannot find symbol
symbol: variable i
location class parent.
Then I replaced the i with public variable j, assuming because it was declared protected it gave compilation error, but still for variable j, even though it was declared as public it gives the same compilation error. can anybody throw some light on it please.
much appreciated
thanks in advance
Suresh.
Harshit Rastogi
Ranch Hand
Joined: Apr 15, 2008
Posts: 131
posted
0
To access i variable this line is wrong.
Since the child class is in different package , you extend parent to inherit it.
you dont need to create parent object.
use the following line:
He had a excellent query(accessing outer package from inner package) after several attempts he got the answer for that!
you have to just include the java -cp <path> <filename.java> command to compile
. for current directory
.. for parent directory
you can use these relative naming pattern for setting appropriate path
Also have you placed the second file in a package or not .i suppose you have not !
Also most people do not know protected fields are accessible only through inheritance,you cannot make a reference and access a protected field i suppose this is not the major cause as you were saying it gives same error when field is changed to public !so it got to be the classpath problem please read the above and if you have time read the Package Problem from Ashutosh Chauhan!
Not good.
Please check your private messages again.
Manish R Singh
Greenhorn
Joined: Mar 14, 2009
Posts: 14
posted
0
Now i have posted my original name i can give you proof for my name
Komal Amaresh
Ranch Hand
Joined: Oct 06, 2008
Posts: 67
posted
0
As you have extended the parent class, its variables can be accesed by the child class. the parent class is in a subdirectory p. so you cannot access it through the object of the parent class. try it by an object of the child class itself.