Click to See Complete Forum and Search --> : calling classes
Judman
May 10th, 2000, 11:33 PM
HI,
Please help.
I hava created a program and want to call the class file to another program I am creating. How do I call it?? I don't want to put both class in one using inheritance.
Thanks for your help.
Judman
dogbear
May 11th, 2000, 06:08 AM
Judman,
Calling a class from another class(or a program) is as simple as this:public class MyClass
{
public int x = 10;
}
public class MyApplet extends Applet
{
// declare your MyClass Object
MyClass myClass = new MyClass();
public void init()
{
// initialize MyClass
myClass.x = 20;
}
}
Note: The MyClass class should be in a file called MyClass.java and the MyApplet class should be in a file called MyApplet.java.
You should have both files in the same directory OR in your java classpath.
Hope this helps,
dogBear
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.