Avatar of jagguy
jagguyFlag for Australia asked on

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
Java

Avatar of undefined
Last Comment
nareshvoota

8/22/2022 - Mon
nareshvoota

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.
ASKER
jagguy

yes that is what I want.
IN netbeans how do I do this as their is no add file/class to the project
nareshvoota

What version of net beans are you using?
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
jagguy

most recent 7.1
ASKER CERTIFIED SOLUTION
nareshvoota

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question