A
arya
hi guys, I am facing problem with accessing protected members of
parent(base)class in child (derived) class.It's give me compile time
error (Filed s is not visible )when i am trying to access field s in
parent class from within child class.
My code is as follows :
(1) Parent Class :
package com.parent;
class My{
String s = "My";
}
(2)Child Class :
package com.child
import com.parent.My
public class Test extends My{
protected String s = "Test";
public static void main(String[] args){
My my = new My();
System.out.println(my.s);// give me compile time error here
specifying that "field"
} // is not visible
}
please help me.... Can't I access protected members of the class from
within subclass in different package ?
parent(base)class in child (derived) class.It's give me compile time
error (Filed s is not visible )when i am trying to access field s in
parent class from within child class.
My code is as follows :
(1) Parent Class :
package com.parent;
class My{
String s = "My";
}
(2)Child Class :
package com.child
import com.parent.My
public class Test extends My{
protected String s = "Test";
public static void main(String[] args){
My my = new My();
System.out.println(my.s);// give me compile time error here
specifying that "field"
} // is not visible
}
please help me.... Can't I access protected members of the class from
within subclass in different package ?