Creating Objects and Calling Methods in Java
In this class, We discuss Creating Objects and Calling Methods in Java.
The reader should have Intuition in Class and Object. Click Here
We take an example and understand how to create an object and call methods.
Example:
The below diagram shows the complete code.
The example has two classes.
The first class name is “firstexample”.
The second class name is “test.”
The file name and second class name are the same.
In the test class, we have a main method.
The main method is static.
The execution starts from the main method.
The line firstExample ob = new firstExample() is used to create an object for the class “firstExample.”
“ob” is called a reference variable.
The keyword new is used to create a memory allocation to the class.
Once the memory is created, we can use the methods present in the class.
How is memory allocated to objects and methods discussed in our next class?
“ob. add(1,5)” is used to call the add method in class “firstExample”.
The execution moves from the main method to add method.
After completion of add method, the execution continues in the main method.
When we call the mult method, we use variable z to store the return value.
The value z is displayed in the last line of code.
Link for playlists:
/ @wisdomerscse
Link for our website: https://learningmonkey.in
Follow us on Facebook @ / learningmonkey
Follow us on Instagram @ / learningmonkey1
Follow us on Twitter @ / _learningmonkey
Mail us @ learningmonkey01@gmail.com
En esta página del sitio puede ver el video en línea Creating Objects and Calling Methods in Java || Lesson 32 || Java Programming || Learning Monkey || de Duración hora minuto segunda en buena calidad , que subió el usuario Wisdomers - Computer Science and Engineering 25 junio 2023, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 5,296 veces y le gustó 116 a los espectadores. Disfruta viendo!