how to call another class method in java 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");
    /*Once you type the 'firstGrade.' your IDE most likely 
	will show all the functions it can acess*/
    firstGrade.getTeacherName();
}

Example 2: how to access methods from another class in java

public class Alpha extends Beta{
     public void DoSomethingAlpha() {
          DoSomethingBeta();  //?
     }
}

Tags:

Java Example