• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

classpath

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 179
Mac Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Stop it! You're embarassing me! And you are embarrassing this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic