static data and static methods in java

class JavaExample{
   private static String str = "BeginnersBook";

   //Static class
   static class MyNestedClass{
	//non-static method
	public void disp() {

	   /* If you make the str variable of outer class
	    * non-static then you will get compilation error
	    * because: a nested static class cannot access non-
	    * static members of the outer class.
	    */
	   System.out.println(str); 
	}

   }
   public static void main(String args[])
   {
       /* To create instance of nested class we didn't need the outer
	* class instance but for a regular nested class you would need 
	* to create an instance of outer class first
        */
	JavaExample.MyNestedClass obj = new JavaExample.MyNestedClass();
	obj.disp();
   }
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to static function in static method java when do we use static methods in java java when to use static methods what is static method and variable in java static class and static method in java static and non static method in java how to use this in static method java why do we use static methods in java example of static variable and static method in java what's the purpose of static methods and static variables in java static variables and static methods in java when to use static methods in java when to use static in java when should we use static methods in java java using static methods when should you use a static method java static method keyword in java how to create static methods without using static variables java java static variables and methods static and non static methods java purpose of static methods and variables in java when should you use a static method in java why create static methods in java when to use static methods java write static method in java usage of static method in java what does static method mean in java creating a static method in java where does the static data in java gets stored use static methods java static function in java why we use static in java static method called in java what is static method in java with example static variable static method java what is the static in java java static method example why to use static method in java where static methods are stored in java what is the significance of static methods in java static and non static methods in java\ static functions in java static data members in java java what are static methods when do i have to use static methods in java Can we use the static variables inside static methods in java what are static methods java create static methods in a dynamic class java what happens when all methods are static in java should data be static in java should data be static java java memory static variables stored java static methods when to use static methods in java and non static static and non static methods in java how static method works in java accessing a static method in java static data and static method in java with example when are static methods created in java what is static data in java java program with static method static methods in java what are static methods in java what is a static variable/method in java making a method static in java static in method java means example of static method in java static methods and variables in java static variable and static method example in java static variable and static method in java example static variable and static method in java how to use static methods in java what is a static method in java accessing static methods of a class in java static variables java static method in java static variables and methods in java static variables in java static variable java what is a static variable in java Static Methods and Member Variables in Java static method static method use in java static variale what is a static variable static variable Static variable can be used in static method. java static variable usage when is static keyword used can static methods be called using object in java java func static what is a static variable java static method java static methods java static methods on Java what are static variables in java static keyword memory allocation in java How to create a static method inn java static data in java static methods in java java static member function static methods in java examples static methods in java example static variable in java what is static method in java java static method How to use static methods java static data and static methods in java
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source