Hi! Thanks you all for the replies- Tushar Goel, Stuart A. Burkett, and, Campbell Ritchie!!
Tushar Goel wrote:I suppose you need to set class path for the same as they are on different path ... .
Do you mean compiling the TestingCars class using the option '-classpath', like, >javac -classpath...? I tried this but I am not able to put the classpath locations correctly while compiling, and, because of that, the class in the same directory (Car.java) is not getting found. I think this is also one way in which these programs can be executed without getting any errors... I will see later about how to put the classpaths correctly.
I am using the directory structure as follows:
Stuart A. Burkett wrote:
Do you have any package statements in your classes ? ... .
No, I did not put any package and import statements in the classes. After reading this, I put the appropriate package and import statements in the classes and there is no error now, and, the programs are working fine!
I thought that if a class is public and is in the sub-folder of the running class, then, there might not be any need of importing it by putting package and import statements in the classes- because the class is 'public'- but, maybe it is not like that, Right?
Campbell Ritchie wrote:… or put all the XXX.java files in the same directory.
Yes, sir, if the classes are put in one single directory, the programs work fine without any errors. And, in that case, there is no need for putting package and import statements in the classes. The coding exercise that I was doing told to put the classes in different packages, so, I was trying to access the class from a different package.
Is it necessary to put import statements for accessing classes that are 'public' and in the sub-folder from where the current class is?
Thank you all!