Basics Of Java Programming|static Vs Non Static Variable-methods In Java

To call it revolve again I can do that now it’s not dependent on the object right it doesn’t require any object for its execution but.

Instead now if I remove the static in front of this method now it requires.

The object say it’s saying cannot make a static reference to a non static method Raval okay so now it requires object so basically you know whenever you make any variable static any method static it doesn’t depend on its object of the class.

It’s independent it can be directly used without any object reference okay so that’s the main difference among static in a non static method that a static method for its execution requires an.

Object but and a static model does not require it but a start and non.

Static method requires that.

Printname is a non static method that’s why it requires an object for its execution but revolve method is static that’s why it doesn’t require any object okay simple as the same same thing of all.

The variables like we have discussed and again if we talk about there are the static method so in the java libraries itself there are so many methods that are static okay there are pre-existing methods that are static if we take.

An example I’ll show you the example of it okay so now let’s just see another example of a static function that is pre-existing within the rest Ishod itself we are going to you know use so many methods that.

Are present in restaurant libraries that have static so let’s see how we use those pre-existing static methods so I’ll create a new class here and I’ll give it nameless just static example okay so you know in Java there is a pre-existing liability called land within that we have.

That has so many mathematical functions suppose one of them that we’ll use is the out of two integers finding the minimum or the maximum number okay so suppose in this class I have two integers present so let’s say int eh okay and.

Let’s give it a value which are the value 10 and there is another integer int variable present which is equals to 4d okay so now I’ll create the main method and when didn’t mean I.

Have want to find out the number which is you know maximum out of these or the biggest number out of these two number or let’s say the minimum so I can use the pre-existing methods that are present in the Java library and I don’t have to create any object for it I can directly use it as soon as I’ll do the import okay so I know the library where.

That mixin maximum minimum function exists so I will just simply import it while importing it.

As I told you that these methods are static so again you have to make an static input so I will use import static now the name of that library so it’s in the Java dot lang okay within that.

It’s Matt and within math the function that I want.

To import is let’s say max I wrote that function and that is for the integers you see here okay now here I can directly use that method no object nothing directly called that method and use it this pass the integer values and it will give you the maximum value out of it maximum or let’s say the minimum value out of it okay okay.

Programming

Related Articles

0 Comment