Static members in Java

Previous
Next

Static members:

  • Every application has 2 Contexts
    • Static
    • Non static
  • Program execution always starts with Static Context
  • Static – Common area to access in the application.
  • Java Supports 4 static members
    • Static main() method
    • Static block
    • Static variable
    • Static user method

Empty class:

class Pro 
{
	// Empty class
}

Save file as :  Pro.java
Compile : No error
Run : Error : No main() method to start

Main() method:

  • Every java program execution starts with main() method.
  • If we don’t define main(), JVM gives runtime error.
  • Main() automatically executes by JVM.
class Pro 
{
	public static void main(String args[])
	{
		System.out.println("Main method");
	}
}
Previous
Next

Add Comment

Courses Enquiry Form