Classes on Java?

+1 vote
asked Aug 4 by (130 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 by (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.
...