class - Interfaces: Java Language Specification -
please explain:
- 3rd bullet point
- 5th line (in bold)
- 2nd last line
every class in java implicitly (or explicitly) sub type of java.lang.object
.
the class object superclass (§8.1.4) of other classes.
because of this, can invoke method declared in object
on variable of class type.
string var = ...; var.hashcode();
this has true interface
type variables well
someinterface var = ...; var.hashcode();
for reason, interface
must implicitly declare (as abstract
) methods declared in java.lang.object
.
you can't override final
methods, interface declares methods must implemented in sub types, compile time error thrown if interface declares method declared final
in java.lang.object
.
an interface can declare classes, interfaces, , fields in body. if sub interface declares of same name, hiding those. therefore doesn't inherit them.
for example,
public static void main(string[] args) throws exception { system.out.println(parent.answer); system.out.println(child.answer); } interface parent { int answer = 42; } interface child extends parent { int answer = 0; }
prints
42 0
there no way parent
's value child
reference.
Comments
Post a Comment