0
Method calling
how can i use the method calling properly in java
2 Respuestas
+ 4
1. Defining a Method
public class MyClass {
// Method definition
public void myMethod() {
System.out.println("Hello from myMethod!");
}
}
2. Calling a Method
public class MyClass {
public void myMethod() {
System.out.println("Hello from myMethod!");
}
public void anotherMethod() {
myMethod(); // Calling myMethod from anotherMethod
}
public static void main(String[] args) {
MyClass obj = new MyClass();
obj.anotherMethod(); // This will call anotherMethod, which calls myMethod
}
}
+ 5
methodOfThisClass();
object.method();
ClassName.staticMethod();
package.path.ClassName.staticMethod();