help you means help me
Arathi<br />Sun Certified Java Programmer
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Originally posted by Arathi Rajashekar:
I have a doubt. I modified the above code to following. It is compiling fine
class A
{
protected int i = 10;
public int getI() { return i; }
}
public class B extends A
{
public void process(A a)
{
a.i = a.i*2;
}
public static void main(String[] args)
{
A a = new B();
B b = new B();
b.process(a);
System.out.println( a.getI() );
}
}
But if I make class A as public its not compiling.Even when i saved it in file A.java, while compling B.java it says class A not found.
Am bit confused here. Can anybody give clear idea on this. The above code will be in same package. So if it is in same package can we access protected variables using super class reference.
[ January 08, 2002: Message edited by: Arathi Rajashekar ]
help you means help me
Originally posted by Seany Iris:
class B is subclass of class A,why cannot it accesses the variables of A?
Rob
SCJP 1.4
Rob
SCJP 1.4
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |