This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I interpret your question as, "how does one class use another class".
class A, has to initialise class B in order to use the operations B offers (that is, it's public interface).
If you paste the above in a file called A.java and compile it (javac A.java) and run it (java A) you'll see "Im class B!". A uses B's print class. It cannot use B's myOwnMethod however, since it's private.. but B can use it itself.
Hope the above helped.
Joined: May 18, 2005
it's that simple? Thanks. I'll apply and practice. Thank you very much
Originally posted by Lawrence Buensalida: it's that simple?
Err no not really. The example given was the simplest form of calling a method from one class by another. Read up on packages and on the different forms of encapsulation in Java. What would of happened if the method had been static, for example? Here is a link to the
Java Tutorial. Also how do you need to modify your classpath when calling a method from a class within a Jar file?