Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

classpath

 
Vierda Mila
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

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


compile Horse.java


running Horse.class


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??)

So confusing, really appreciate for your reply.
 
Swapnil Sonawane
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because your Horse class extends your Animal class. It has its own class file. Am I clear?
 
Vierda Mila
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Swapnil,

thank you for your reply, but I'm still not clear about this. regarding this thread, it not necessary to mention the parentclass when using the classpath, or am I wrong or missing something??
 
Ravikanth kolli
Ranch Hand
Posts: 179
Chrome Eclipse IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question isn't really about the SCJP exam, so I am moving it to the Java in General (Beginner) forum.
 
Joe Fischer
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does not mean that you will not see something like this on the certification exam. Things like this was on the Java 6 exam, at least.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic