This is my first question on stackoverflow,
I want to access static int variable of one class in another class but when i access this variable in another class it always gives me "zero".
This is First class:
package kk; public class ag { public static int n=0; public static int as() { return n; } public static void main(String[] args) { // TODO Auto-generated method stub n=3; n=n*5; System.out.println(n); } } Here the output is 15 i.e. n=15 here.
Second class:
package kk; public class ah extends ag { public static void main(String[] args) { // TODO Auto-generated method stub //ag aa =new ag(); int k =ag.as(); System.out.println(k); } } In this am trying to access the static variable n from First class but getting 0 as output but i want 15.
ahthe value will be initialized to 0 and never changed