• Post Reply Bookmark Topic Watch Topic
  • New Topic

Use this class....  RSS feed

 
Manuel Diaz
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have in another file a class called "Mine". Is there a way where I can call that class from my program? I want to run the code inside the class.
 
Svend Rost
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me get this right - your file "MyClasses.java" looks like this:


In order to get access to the class Mine, you simply instantiate an object
of type Mine, as you would with any other classes..

Give it a try, and if doesn't work, feel free to reply.

/Svend Rost
 
Manuel Diaz
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I have in the class "mine" a method called "print", the method is only to print a line of text, like this:



Now on my real ".java" file called "original" I want to access to that method on the class "Mine". BUT.... the class "Mine" is not on the same file as "original". "Mine" is another ".java" file. Suggestions?
 
Svend Rost
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As long as the two classes, ClassA and ClassB, are in the same directory, they can "see" each
other, and you can therefore in, say ClassA, instantiate objects of type ClassB
and or call classB's static methods. They don't have to be in the same file,
nor do they have to be in seperate files.

How do you instantiate an object?
<ClassName> <objectName> = new <ClassName>



Place the two files in the same directory, and compile (i.e. "javac <filename>
and run them (i.e. "java ClassA")

Hope the above helps

/Svend Rost
[ May 29, 2005: Message edited by: Svend Rost ]
 
Manuel Diaz
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you all, I got it now.
 
Nigel Browne
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may like to read this information on interfaces and packages from the java tutorial.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!