As part of learning, here is the pathological example below that am trying to understand,
class C{}; interface I{}; class S extends C implements I{};
class B{};
With these declarations, I can say that, class C
class B
are immediate subclass of Object
class and can access all methods of Object
class from within those classes. But,
1) When i declare interface I{};
How is interface I
related to Object
class?
In continuation, Below are some assignment to array types, followed by subclass to super class assignment and vice-verse.
C[] c = new C[4];
S[] s = new S[6];
I[] i = new S[0];
B[] b = new B[2];
//i = new C[2]; Compile error
i =s; c=s; s = (S[])c; i = (I[])c;
i = (I[])b; //Run-time error
I learnt that arrays are 'first class objects' and immediate subclass of Object
class,
Object o = c; // i mean `I i = c;` will not work `I[] i =c;` works
2) With respect to above definition(syntax), What is the meaning of 'arrays are first class objects'?Because Object[] oa = c;
make sense to me as class C
is immediate subclass of Object
class.