Wednesday, December 7, 2022

How to create and call Java non static method | Tutorial for Beginners

 In this java beginners tutorial we will learn about how to create and call non static method step by step .  This is very important concept we will create method and will call in main method if you want to watch video in either English or Hindi Language click on below link. 

Java Tutorial in English Language
Java Tutorial in Hindi Language

We will create method in same class . So first let create class. 

As seen in above picture we have created class and check mark on public static Void main and click on Finish. Now we will get auto generated main method in Java. 
Now create method in same class. 

public void myFirstMethod(){
System.out.println("Hello This is my Method");

To create method we use public access modifier so we can access in same package. We are not returning anything so we have used void word. we provide name of method and bracket and then curly brace , where inside we will write out logic. For now we are just printing Hello.....method but later we will play this in next tutorial.  
So java non static method creation is done now we have to call this method . So lets learn how to call this method?
if we would have use static method we do not need to create object instead we can call directly by using class name however this is not static method so we have to create object.
myJavaNonStaticMethod mjm = new myJavaNonStaticMethod();

In the main method we will use same name class name and create variable and them we use = for assignment and new word and class name and bracket . now we store object in variable named mjm. If we type mjm and then dot we will get all method which we can access of them but for now we will select method which we created earlier . 

Now we run this method , for running method we will click on green arrow if eclipse observe out put. 

we can observe we got output as we expected. if you want to learn more here is link of few more videos .


Structured Self-Development (SSD) Level 2 Module 1, 2, and 3

Assignment of Arithmetic Operators Java | Tutorial for Beginners

  In this tutorial you will learn how to create and call non static method . We will create method and do operation of addition, subtraction...