You need to compile B.java that is in the package xcom. class B needs class A because it extends class A. Class A and B are in the same package xcom.
Important point: You tell the compiler the directory path that consists the package and not the package itself. It is the most mistaken thing people assume.
For this example you have to tell the -cp as . means current directory, current directory is test and that consists the xcom package. And to refer to the B.java you say xcom/B.java because it gives the complete path to the B.java from test directory. Compiler can find class A also in this way because of (-classpath .).
Thanks Chandra for reply. But in this example, if test is current directory, how can compiler find A.class file from test directory as it is in a xcom package.Because(. xcom/B.java) is for finding B.java file not for A.class.
It seems you didn't take the vital part of the issue: OK! See what Ivor Horton says in his book Beginning Java 2:
The path to the package directory is the path to the directory that contains the package directory, and therefore does not include the package directory itself. for example, if you have stored the source files for classes that are in the Geometry package in the directroy with the path C:\Beg Java Stuff\Geometry, then the path to the Geometry directory is C:\Beg Java Stuff. Many beginners mistakenly specify the path as C:\Beg Java Stuff\Geometry, in which case the package will not be found.
I have made the statement in bold face, where you miss the point to understand.
It seems that test directory is on your classpath, so that compiler finds class A. You can compiler class B being inside xcom directory; NO problem! suppose you want to compiler class B from being C: drive you do like: