I have Class1 in package1 which is public. Now I want to create Class2 in package1. Do I need to import package1 in Class2 ?
Class2 in package1 is protected. I am creating Class3 in package1. I can not instantiate Class2 in Class3. Can I extend Class2 in package2 (public class Class3 extends Class2) ?
I have Class4 with default access specifier (in package1class Class4). Can this class be extended by Class3, which is in package2 ?
Class1 has an integer field as protected, "protected int i". Can I use this field in Class3 ?
There is a private
String str in class1. Can I use this field in the main() of Class1 with the referance of Class1 ? (Class1 c1 = new Class1(); c1.str;) ?
OR do I need to access str through a public method of Class1 even in the main() of Class1 ? I understand that if I am accessing str in a different class, then I have to use method of Class1 to access private str, but does it apply to the main() of Class1 also ?
Thanks