

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
all concepts are illustrated with example and difference b/w stactic and non static methods is also explained
Typology: Thesis
1 / 3
This page cannot be seen from the preview
Don't miss anything!
Basics of Java
JP - History of Java
JP - Overview of Java
JP - Basic Points
JP - Features of Java
JP - Environment Setup
JP - Path vs Classpath
JP - Platform Independent
JP - First java Program
JP - Compile and execute
JP - JDK JVM JRE
JP - JVM Architecture
JP - Object and Class in Java
JP - Datatypes in Java
JP - Variables in Java
JP - Operators in Java
JP - Java Program Structure
JP - Main() Method
JP - CMD Arguments
JP - SOP Statements
JP - Decision making statements
JP - Looping statements
JP - Wrapper Classes
JP - Naming Conversion
JP - Import Statements in Java
JP - Access Modifiers in Java
JP - Array in Java
Java Useful Keywords
JP - Final Keyword in Java
JP - Static Keyword in Java
JP - This Keyword in Java
JP - Super Keyword in Java
Prev Tutorial Next Tutorial
In case of non-static method memory is allocated multiple time whenever method is calling. But memory for static method is allocated only once at the time of class loading. Method of a class can be declared in two different ways
Non-Static method Static method
These method never be preceded by static keyword Example:
void fun1() { ...... ...... }
These method always preceded by static keyword Example:
static void fun2() { ...... ...... }
2 Memory is allocated multiple timewhenever method is calling. Memory is allocated only once at the time ofclass loading.
3 It is specific to an object so that theseare also known as instance method. These are common to every object so that it isalso known as member method or class method.
These methods always access with object reference Syntax:
Objref.methodname();
These property always access with class reference Syntax:
className.methodname();
If any method wants to be execute multiple time that can be declare as non static.
If any method wants to be execute only once in the program that can be declare as static.
Note: In some cases static methods not only can access with class reference but also can access with object reference.
Example of Static and non-Static Method
Example
class A { void fun1() { System.out.println("Hello I am Non-Static"); } static void fun2()
Advertisements
HOME C C++ DS Java AWT Collection Jdbc JSP Servlet SQL PL/SQL C-Code C++-Code Java-Code Project Interview (^) Custom Search S
Html Html5 CSS JavaScript Ajax JQuery AngularJS JSON GMaps Adsense Blogger Earning Email Domain SEO SMO (^) ABOUT | SERVICES | FORM S | C
JP - Java Home
-40%
Rs 475
JP - Synchronized Keyword
JP - Volatile Keyword
Java classes & constructor
JP - Static Block in Java
JP - Inner Classes
JP - Abstract Class
JP - Static & n-Static Variable
JP - Static & n-Static Method
JP - Constructor in Java
JP - Relationship In Java
Java Object Oriented
JP - OOP's Concept
JP - Inheritance
JP - Overloading in Java
JP - Overriding in Java
JP - Interface in Java
JP - Abstraction in Java
JP - Encapsulation in Java
JP - Polymorphism in Java
Java Advanced
JP - Package
JP - Exception Handling in Java
JP - Multithreading
JP - String Handling
JP - StringTokenizer
JP - Data Conversion
JP - Boxing and Unboxing
JP - Scanner Class
JP - Applet
JP - Factory Method
JP - Java Networking
Java Tools
Java Interview Question
Java Difference Between
System.out.println("Hello I am Static"); } } class Person { public static void main(String args[]) { A oa=new A(); oa.fun1(); // non static method A.fun2(); // static method } }
Output
Hello I am Non-Static Hello I am Static
Following table represent how the static and non-static properties are accessed in the different static or non-static method of same class or other class.
Example
class A { int y; void f2() { System.out.println("Hello f2()"); } } class B { int z; void f3() { System.out.println("Hello f3()"); A a1=new A(); a1.f2(); } } class Sdemo { static int x; static void f1() { System.out.println("Hello f1()"); } public static void main(String[] args) { x=10; System.out.println("x="+x); f1(); System.out.println("Hello main"); B b1=new B(); b1.f3();