I found difficulties when I learn about classpath, it's really confusing. please find below example from my self code.
My directory structure as per below :
After several attempts, I have compiled and running above code and it was running well, here is the code : compile Animal.java
My question is why I have to specify the Animal class when I compiled and run the Horse? why I can't do it like this--> C:\Documents and Settings\Mila\Desktop\project> java -cp .\com\path;. Horse (no Animal added, only the classpath for animal??)
the reason why you need to specify the base class in the path to run the sub class is because both of them are in different packages. As in the example above Animal class is in the package com.path while the Horse class is in the default package.
If both the classes are declared in the same package, then we need not add the base class in the path.