You should capitalize names of your classes. After doing that do this in your school class,

Classroom cls = new Classroom();
cls.setTeacherName(newTeacherName);

Also I'd recommend you use some kind of IDE such as eclipse, which can help you with your code for instance generate getters and setters for you. Ex: right click Source -> Generate getters and setters

Answer from ant on Stack Overflow
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ [java]- calling on a method from another class
r/learnprogramming on Reddit: [Java]- Calling on a method from another class
June 21, 2015 -

I am new to Java, and am currently studying how to create packages with related classes in Eclipse.

If I create one class (example: Circle) defining the methods ( writing()) I want to use, and another class using those methods, do I have to include a reference to an instance of that class? Here is a code example of what I mean:

public class Circle{ 
    double r; 
    void wirte() { 
         Syste.out.println("Hello");
    }  

and in the other class:

public class Circle2{ 
     public static void main(String[] args) { 
          write(); 
  }} 

Would that work? Or do I always have to follow that format: classinstance.methodname()?

๐ŸŒ
Reddit
reddit.com โ€บ r/javahelp โ€บ how to call a method in another class from the main class?
r/javahelp on Reddit: How to call a method in another class from the main class?
April 20, 2023 -

UPDATE

I did not know I can do something like this

public class GUI(){
//do something
}

public static void main(String[] args){
   new GUI();
}

This code block worked for me --- thank you for pointing it out.

---------

So my IDE flagged an error at this line in main (from my main class Tic_Tac_Toe)

public static void main(String[] args) {

        ColRowLists ttt = new ColRowLists();
        char[][] board = new char[3][3];
        System.out.println("Welcome to Tic Tac Toe");
        userInput(board);

        System.out.println("show me your list" + ttt.winOrLose()); //"'winOrLose(java.util.List, java.util.List, java.util.List, java.util.List, java.util.List, java.util.List, java.util.List, ...)' in 'ThirtyMinutes.ColRowLists' cannot be applied to '()'"


    }

The winOrLose method in question lies in another class ColRowList: https://github.com/morry239/TTT_experiements/blob/master/src/ThirtyMinutes/Tic_Tac_Toe.java

I tried to do something like this, but it did not work obviously:

System.out.println("show me your list" + ttt.winOrLose(List topRow, List midRow, List botRow, List leftCol, List midCol, List rightCol, List diagonal1, List diagonal2);

Could anyone kindly point me in the right direction? My main class is here FYI.

๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ java โ€บ how to call a method in another class in java
How to Call a Method in Another Class in Java | Delft Stack
February 2, 2024 - A method declared as the public is available for outside access and can be called into another class. Here, we called a public method getName() into another class by using the object of Student class.
๐ŸŒ
Liberian Geek
liberiangeek.net โ€บ home โ€บ how-to/tips โ€บ call a method from another class in java
Call a Method from Another Class in Java | Liberian Geek
June 12, 2026 - To call/invoke a user-defined method from another Java class, create an object of the class containing the method and call/invoke the particular method via the created object.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ in-java-can-we-call-the-main-method-of-a-class-from-another-class
In Java, Can we call the main() method of a class from another class? - GeeksforGeeks
July 12, 2025 - But calling the main() method from our code is tricky. It can lead to many errors and exceptions, such as: The main() method must be called from a static method only inside the same class.
๐ŸŒ
Quora
quora.com โ€บ How-can-I-call-a-class-from-another-class-in-Java
How to call a class from another class in Java - Quora
Answer (1 of 21): First import the class. [code]import packageName.ClassName; [/code]If the method is static, you could simply do this: [code]ClassName.method(); [/code]If it is not, you need to create a new object and call it on that: [code]ClassName c = new ClassName(); c.method(); [/code]Fo...
๐ŸŒ
Linux Hint
linuxhint.com โ€บ call-invoke-method-from-another-class-java
How to call a method from another Class Java โ€“ Linux Hint
In Java, a method can be invoked from another class based on its access modifier. For example, a method created with a public modifier can be called from inside as well as outside of a class/package. The protected method can be invoked from another class using inheritance.
Find elsewhere
๐ŸŒ
JavaBeat
javabeat.net โ€บ call-java-method-from-another-class
How to Call a Java Method From Another Class?
January 31, 2024 - This means you can access or call a static method of one class to another class directly by using the class name. The accessibility scope of the static method depends on the access modifier used with it, such as public, private, etc. Letโ€™s create a class โ€œExample1โ€ with a static method ...
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 377430 โ€บ java โ€บ Calling-method-class
Calling a method in another class (Java in General forum at Coderanch)
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums ยท this forum made possible by our volunteer staff, including ... ... I am not clear on all the ways to do this. We have done it in a Cup and Cupboard senario where, in Cupboard class, we called a getColour and a getYear from the Cup class, but in this case, the Cupboard class had a constructor that had cup1, cup2 and cup3 as instance variable.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 706451 โ€บ java โ€บ Call-method-class
Call method from other class (Beginning Java forum at Coderanch)
February 17, 2019 - Because that's how Java works. public static methods can be called from anywhere by supplying the name of the class that the method is defined in. So the code above says: "Call the static method updateCountDownText() defined in class MainActivity" HIH Winston But like you say the method is ...
๐ŸŒ
RoseIndia
roseindia.net โ€บ java โ€บ javascript-array โ€บ call-method-another-class.shtml
Java call method from another class
class of CallingClass.java file has to created inside the class of MainClass.java file as shown in the example. ... inside the class of MainClass.java file. Its very easy to access the methods of the class CallingMethod.
๐ŸŒ
JanbaskTraining
janbasktraining.com โ€บ home โ€บ how to call a method in java?
How to Call a Method in Java from another or Same Class?
May 20, 2019 - Multithread Support: Multiple threads of execution are supported by Java, which also includes a set of synchronization primitives. This helps in making the programming easier by threads. Modifiers: modifiers usually change the behavior of the class. E.g., private, public, etc. A method can have more than one modifier attached to it. g., you may want to use the private and static together but calling a non-static method from a static method is not possible as the former is linked with the object while the static method is linked with the class.
๐ŸŒ
IncludeHelp
includehelp.com โ€บ java โ€บ how-to-call-a-class-from-another-class-in-java.aspx
How to call a class from another class in Java?
March 23, 2024 - // accessing class in another class by using // Fully Qualified Name public class MyClass { public static void main(String[] args) { // Creating an instance of ArrayList by using // Fully Quaified Name java.util.ArrayList al = new java.util.ArrayList(); // By using add() method to add few elements // in ArrayList al.add(10); al.add(20); al.add(30); al.add(40); al.add(50); // Display ArrayList System.out.println("ArrayList :" + al); } }
๐ŸŒ
Quora
quora.com โ€บ How-do-I-use-method-from-another-Java-class
How to use method from another Java class - Quora
Answer (1 of 15): It depends on what behaviour you want and what access level there is. All below access modifiers can be used with methods (and not only :) Access Modifiers ( private, public, protected, default) Non-Access Modifiers (abstract, final, static, synchronized(thread safe), violate ...
๐ŸŒ
Code Underscored
codeunderscored.com โ€บ how-to-call-a-method-from-another-class-in-java
How to call a method from another class in Java
By using inheritance, a protected method can be invoked from another class, whereas a static method can be invoked from some other class by using the class name. Private methods canโ€™t be called into any class since they are limited to the ...
๐ŸŒ
YouTube
youtube.com โ€บ watch
Calling methods from other Class in JAVA for beginners ! - YouTube
Calling methods from other Class in JAVA for beginners !How to call methods from other Class in JAVA | A video tutorial for beginners. In this video we learn...
Published: April 7, 2020
๐ŸŒ
YouTube
youtube.com โ€บ watch
How To Call A Private Method In Java (And Access From Another Class) - YouTube
$1,500 OFF ANY Springboard Tech Bootcamps with my code ALEXLEE1500. See if you qualify for the JOB GUARANTEE! ๐Ÿ‘‰ https://bit.ly/3HX970hIn this video, I show ...
Published: May 25, 2023
๐ŸŒ
Team Treehouse
teamtreehouse.com โ€บ community โ€บ calling-method-from-another-class
Calling method from another class (Example) | Treehouse Community
January 26, 2015 - I'd also avoid using the name main for a method because if it has the signature: ... It will be treated as the entry point of the application. Assuming you're trying to build something like a quiz app, here's a simple data model for a question that you could start with: public class Question { private String mPrompt; private String mAnswer; public Question(String prompt, String answer) { mPrompt = prompt; mAnswer = answer; } public String getPrompt() { return mPrompt; } public String getAnswer() { return mAnswer; } }