Implicit access modifiers in interface:
>>All the variables defined in an interface must be static final, i.e. constants. Happily the values need not be known at compile time. You can do some computation at class load time to compute the values. The variables need not be just simple ints and Strings. They can be any type.
>>All methods in an interface are implicitly declared public and abstract. All variables in an interface must be constants. They are implicitly declared public static final.
>>Interface is abstract, but not vice versa. There should be nothing implemented in interface. Abstract class can be partially implemented.
>>A class can only extend one class; abstract class is included.
>>A class can implement multi interfaces.
Can abstract class and interface have static method:
Ex:
abstract class A {
// OK
static void doSomething() {
}
// illegal combination of modifiers: abstract and static
//abstract static void doOtherthing();
}
interface B {
// modifier static not allowed here
// static void doSomething();
}
static and interface:
1) Inner interfaces are implicitly static, no matter you put static modifier or not. Attention: inner interfaces are very rarely used.
2) Outer interface are NOT static, just like outer class.
3) All members (attributes & methods) of interface are implicitly public.
4) All attributes defined in interface are implicitly static and final.
5) All methods defined in interface are NOT static.
6) All classes defined in an interface are implicitly static
abstract class cannot be instantiated.
// The following code will not be compilable
abstarct public class A{
}
// A a = new A();
// a.aMethod();
Friday, June 22, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment