0

Method calling

how can i use the method calling properly in java

8th Oct 2024, 7:44 PM
Lord Robertson Kundu
Lord Robertson Kundu - avatar
2 Answers
+ 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 } }
9th Oct 2024, 11:42 AM
Aramayis Hayrapetyan
+ 5
methodOfThisClass(); object.method(); ClassName.staticMethod(); package.path.ClassName.staticMethod();
8th Oct 2024, 10:23 PM
zemiak