From the JLS details on protected access:
Let C be the class in which a protected member is declared. Access is permitted only within the body of a subclass S of C.
In addition, if Id denotes an instance field or instance method, then:
If the access is by a qualified name Q.Id, where Q is an ExpressionName, then the access is permitted if and only if the type of the expression Q is S or a subclass of S.
If the access is by a field access expression E.Id, where E is a Primary expression, or by a method invocation expression E.Id(. . .), where E is a Primary expression, then the access is permitted if and only if the type of E is S or a subclass of S.
What is the difference between qualified name and field access expression?
If an expression name is of the form Q.Id, then Q has already been classified as a package name, a type name, or an expression name.
The meaning of a field access expression is determined using the same rules as for qualified names, but limited by the fact that an expression cannot denote a package, class type, or interface type.
found the above text in oracle's web site.
so in simple terms:
- Qualified name means which carries parent info in declaration. for e.g. Pack1.Pack2.Pack3.Class1 & Pack1.Pack2.Pack4.Class2
in Pack4, we can access Class1 in either of following ways Pack3.Class1 or Pack2.Pack3.Class1 or Pack1.Pack2.Pack3.Class1, where the last one would be fully Qualified name.
- field access expression is a subtype of qualified name, but as name says, it is for accessing field
So Qualified names may refer to Packge, Class, Interface but not fields, while field access expression would refer only to fields
REF: http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.11 http://docs.oracle.com/javase/specs/jls/se7/html/jls-6.html#jls-6.5.6.2
qualified name
make sense in terms of class name (think of it in terms of static). where as field access expression is like specifying the Fully Qualified Name
in terms of reference of for a particular object of a class including method names.
Example :
public class A
{
public static void method1()
{//does something
}
}
public class B
{
public int dummy;
public void hello()
{
System.out.println("Hello!");
}
}
public class Main
{
public static void main(String[] args)
{
B b = new B();
b.dummy=1;
b.hello();
}
}
here in the above classes if we say
A.method1()
it is more of a qualified name, where as
b.hello();
b.dummy
is more of a field access expression.
来源:https://stackoverflow.com/questions/15354816/what-is-the-difference-between-qualified-name-and-a-field-access-expression