+ 1
access protected variable in another package in java
hi i have two pkg (protect,otherpkg) otherpkg package: package otherpkg; public class opkg { protected int m = 0; } and , protectpkg : package protect; import otherpkg.*; public class Protect { public static void main(String[] args) { Myclass myclass = new Myclass(); } } class Myclass extends otherpkg.opkg { Myclass() { otherpkg.opkg p = new otherpkg.opkg(); p.m = 70; System.out.println(p.m); } } but i got error in line: p.m = 70; why?
3 Answers
+ 2
Jazz
It is a test example to how access protected member
+ 1
So for access to "m" i use the public method in otherpkg OR protect pakage?
+ 1
Ok understand thanks