jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Please teach me... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please teach me..." Watch "Please teach me..." New topic

Please teach me...

Lawrence Buensalida
Ranch Hand

Joined: May 18, 2005
Posts: 38
I'm new to Java programming and I want to know how to use one class on to another class. Please teach me. Thanks.
Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Hi Lawrence,

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

Hope the above helped.


Svend Rost
Lawrence Buensalida
Ranch Hand

Joined: May 18, 2005
Posts: 38
it's that simple? Thanks. I'll apply and practice. Thank you very much
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
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?
I agree. Here's the link: http://aspose.com/file-tools
subject: Please teach me...
It's not a secret anymore!