9:05 am - Thursday February 22, 2018

Java program to test whether a static method can access the instance variable or not

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

/**

*@author :CandidJava.com

*@descriptions : This program to test whether static method can access the instance variable or not  using java program

*/

public class AccessStaticMethod{

int i;

static int j;

public static void staticMethod(){

System.out.println("u can access a static method");

}

public void nonStaticMethod(){

//i=100;

//j=1000;

System.out.println("n't to access a non static method");

}

public static void main(String[] args) {

//j=1000;

staticMethod();

}

}

Output

D:\candidjava\code>javac AccessStaticMethod.java

D:\candidjava\code>java AccessStaticMethod

u can access a static method

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply