[Java] Call a method from another class
340 viewsThis example shows you how to call a method from another class.
Class #1
JAVA:
-
package basic;
-
-
public class MethodCallingA {
-
-
MethodCallingB MCB = new MethodCallingB();
-
MCB.methodB();
-
}
-
-
}
Class #2
JAVA:
-
package basic;
-
-
public class MethodCallingB {
-
-
public void methodB(){
-
}
-
-
}
After you run class #1 the output will be:
You called the method: methodB












