• Sat. Nov 23rd, 2024

Static member in java

Byskkumar199650

May 23, 2022
java-static-keyword1_img

Static Variables:

Static variables are declared in the class usingStatic keywordStatic variables are by default initialized to its default valueStatic variables has a single copy for the whole class and does not depend on the objects

Static Function

Static functions defined inside the class are qualified with the keyword staticStatic functions can only access static members of the same classStatic function can be invoked using class name and dot operator

Static Class:

We have a class inside a class Which is Known as inner ClassInner class can be qualified with the keyword static.

Example:

public class Example

{

int x://instance member variable

static int x;// static member variable

public void fun1(){}//instance member 

public static void fun2(){y=4}// static member function}

static class Test

{

public static String country=”SKLEARNING”;

}

public static void main(String []args)

{

Example ex1=new Example();

Example ex2=new Example();

Example.y=5;//we also write y=5,because it is in same class

Example.Fun2();

Example.Test.country;

}

}

By skkumar199650

Highly skilled and dedicated Software Developer with over 5 years of experience in developing and debugging applications. Proficient in a wide range of technologies, including .NET Technology, Core Java, MS SQL Server, AWS, Liferay, Angular, Ionic, and Azure, Power BI,SSRS,SSIS. I am passionate about delivering robust and scalable software solutions that meet the highest standards. I thrive in collaborative environments, leveraging my strong analytical and problem-solving skills to drive successful outcomes.