We help IT Professionals succeed at work.

java classes

jagguy
jagguy asked
on
I am using netbeans to program Java.

Can I add classes to a separate file and import this .

Having classes all i  the same file makes for difficult reading
Comment
Watch Question

I hope I am understanding your question right. You can put your classes in different packages.

For example,
Aclass.java file

package com.yourcompany.apackage;

public class Aclass {
    public void doNothing() {}
}

Bclass.java file

package com.yourcompany.bpackage;

import com.yourcompany.apackage.Aclass;

public class Bclass {
    public static void main(String[] args) {
        Aclass a = new Aclass();
        a.doNothing();
    }
}

Hopefully this helps.

Author

Commented:
yes that is what I want.
IN netbeans how do I do this as their is no add file/class to the project
What version of net beans are you using?

Author

Commented:
most recent 7.1
I am attaching an example of how to creating projects, creating packages and creating classes.

To create classes or packages, right click on the project and hit new --> packages.

I used netbeans 7.1 IDE
1.createproject.png
2.testpackage.png
3.writeclassesindifferentfiles.png

Explore More ContentExplore courses, solutions, and other research materials related to this topic.