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 do i create multiple classes in java in gdbonline

+4 votes
asked Oct 13, 2019 by sukant (160 points)

1 Answer

–2 votes
answered Oct 15, 2019 by Theodore Friedrich (290 points)

Java will automatically connect your class files as long as they are within the same directory. In short, just add a new class file, no imports needed. For example, if you wanted a cube class-object, you would have the following two files:

Main.java

public class Main

{

    public static void main(String[] args) {

        Cube c = new Cube(2); // Example object

        System.out.println(c.size);

    }

}

Cube.java

public class Cube

{

    int size;

    public Cube(int size) { // Constructor method

        this.size = size;

    }

}

commented Jun 9, 2020 by João Nelson Cavezale de la Torre (100 points)
Writing your example it shows error as no Cube found
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.
...