Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

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
0
jagguy
Asked:
jagguy
  • 3
  • 2
1 Solution
 
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
 
nareshvootaCommented:
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now