java how to call methods from other classes code example
Example 1: how to call a function from a class java
public class Classroom {
private String teacherName;
public Classroom(String teacherName){
this.teacherName = teacherName;
}
public String getTeacherName() {
return teacherName;
}
}
public static void main(String[] args){
Classroom firstGrade = new Classroom("John");
firstGrade.getTeacherName();
}
Example 2: how to access methods from another class in java
public class Alpha {
public void DoSomethingAlpha() {
Beta cbeta = new Beta();
cbeta.DoSomethingBeta();
}
}