Class 10 ICSE - Java

Static And Non Static in java

In java methods are basically of two types:
  1. Static methods
  2. Non-Static methods
In a static method,here static is basically a keyword.This Static keyword is applied on a variable or method.
Let us understand this by an example:
If Static Keyword is not applied then the method becomes non-static method

Purpose of static & Non-static



When we write a program,we create a variable or method which is stored in small portion of memory as show below.
In that variable or method if static keyword is not applied,means it is non static variable or method.Then if we have to invoke that non-static method or variable ,we have to create an object of a class,by that object you can invoke that method or variable.
When that non-static variable is intialized,it will make different copies again and again and store it in memory.
When static keyword is applied on a variable or method,means it is a static variable or method.Then if we have to invoke that static method or variable,we don't require class object,it can be invoked using the class name only.
It is also called as class method as it belongs to the class rather than object of that class.
Now Let us understand difference between static and non static method with the help of program.
Write a program calculate sum and difference of two numbers.



Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com