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.

Classes on Java?

+2 votes
asked Aug 4, 2019 by Varun Rajesh (140 points)
How do I have multiple classes in Java? I know how to do it in eclipse, but can you do it on the OnlineGDB?

1 Answer

0 votes
answered Aug 5, 2019 by Loki (1,600 points)
Don't make the new class public and you could use its name to call the methods inside the new class from your main.

public class Main

{

public static void main(String[] args) {

System.out.println("Hello World");

newclass.newmethod();

}

}

class newclass

{

    public static void newmethod() {

        System.out.println("This is from the new class' new method");

    }

}

Or you could use a static object to do it (e.g. static newclass obj = new newclass(); to create an object and obj.newmethod() to call the method.)
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.
...