before putting my code what i expect from my code, i wan to know that "if i create a new class in same package in which there are already exist an inherited class. and i want to know that whether i can access those protected field directly from this class, because there are a saying that protected field can be accessed in same package."
Total i created 3 classes and 2 package.
let me clarify that i am doing this all on eclipse ide.
package first; public class Parent { protected int buffalo = 5; // Protected field } package second; import first.Parent; public class ChildClass extends Parent { public static void main(String[] args) { ChildClass a = new ChildClass(); a.buffalo = 10; // Accessing protected field from subclass System.out.println(a.buffalo); // Should print 10 } } // this child class work fine! package second; public class Abhi { public static void main(String[] args) { ChildClass ob = new ChildClass(); ob.buffalo = 20; // i want to access this, here the problem occur System.out.println(ob.buffalo); // and also here } }