Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to make a java project with Main class and other class ?

+3 votes
asked Nov 9 by cw s (160 points)
edited Nov 9 by cw s

How to make a java project with Main class and other class ?

https://onlinegdb.com/PoJWi5QK7

Please, help me to complete that coding....

Thanks.

1 Answer

+1 vote
answered Nov 9 by Peter Minarik (63,320 points)

Every class has to go in its own file with the same name as the class and have a .java extension.

Here's what you need to do:

  1. Rename your file "dstesteq2" to "dstesteq2.java".
  2. Move your dstesteq1 class from "Main.java" to "dstesteq1.java"
Then all will work. :)
commented Nov 12 by cw s (160 points)
Thank you for your kind answer.
It's a good help to me for your advice.
commented Nov 12 by Peter Minarik (63,320 points)
I'm glad you're sorted.

Keep on coding! :)
commented Nov 15 by vaibhav (290 points)
class dstesteq1 {
    int Sub(int x, int y) {
        int z;
        z = x - y;
        return z;
    }
}
public class Main {
    static int Add(int x, int y) {
        int z;
        z = x + y;
        return z;
    }
    public static void main(String[] args) {
        int a, b, c;
       
        //-----------------------------
        a = Add(10, 4);
        System.out.println("a : " + a);
        //-----------------------------
        dstesteq1 eq1 = new dstesteq1();
        b = eq1.Sub(10, 4);
        System.out.println("b : " + b);
        //-----------------------------
        dstesteq1 eq2 = new dstesteq1();
        c = eq2.Sub(10, 4);
        System.out.println("c : " + c);
    }
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...