java classes

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
jagguyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
nareshvootaConnect With a Mentor Commented:
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
0
 
nareshvootaCommented:
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.
0
 
jagguyAuthor Commented:
yes that is what I want.
IN netbeans how do I do this as their is no add file/class to the project
0
 
nareshvootaCommented:
What version of net beans are you using?
0
 
jagguyAuthor Commented:
most recent 7.1
0
All Courses

From novice to tech pro — start learning today.