This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi.. I am an absolute beginner in java.... and I have run in2 a problem....
I have 2 classes c1 and c2.
c1 has.. protected x, protectected c1(), protected void sho();
c2 extends c1..
now c2 has a the main fn...... now i create an object of type c1 inside main;
it works fine as long as c1 and c2 are in same package..... as soon i put them in different packages, they stop working... compiler says... cant access c1() protected access......... i dont understand why...
code.............................................
package p2;
public class c2 extends p1.c1
{
protected int y;
First of all please use code tag for writing code.
You are getting a error because protected variables of a parent class and child class in different packages can be accessed only from the instance of the child class and not parent class.
This is only if the parent and the child class are in different packages.
In your case protected variable of class c1 can only be accessed by instance of class c2 and not c1.
Also, please UseRealWords (not text message abbreviations like "in2"). Thanks! (And try to restrict yourself to a single period "." unless using them as ellipses ("..."))
Amartya Datta Gupta
Greenhorn
Joined: Sep 05, 2010
Posts: 4
posted
0
Thanks!
Amartya Datta Gupta
Greenhorn
Joined: Sep 05, 2010
Posts: 4
posted
0
David Newton wrote:Also, please UseRealWords (not text message abbreviations like "in2"). Thanks! (And try to restrict yourself to a single period "." unless using them as ellipses ("..."))