Email address:
Password:
SCJP/OCPJP 1.6 certification
Practice Exams and Training
SCJP Online Training » Discussions

Class Hierarchy

Can you please explain the points


3. anonymous_class is-NOT-a C.

4. C is-NOT-a(n) anonymous_class.

We have

interface Cat{}
class A{}
class C extends A implements Cat{}


This gives a class structure that looks like this:



This is the statement in the question :


c=(C)new Cat(){};


In this line, we are trying to create an anonymous inner class by implementing Cat. Adding that to our diagram, it would look like this:



As you can see in the above diagram, our anonymous inner class is NOT a sub-type of C, which means it does NOT share an is-a relationship C. On the other hand, C is NOT a sub-type of our anonymous inner class anyway, so there is no is-a relationship in that direction either.


Does that make it a clear?


ExamLab © 2008 - 2024