I have created the following 3 classes. I compile using 'javac
work.java' and the answer is 'Final Result is 2'.
Next, I change the variable in "result" class from "static int count"
to "public int count", and then I compiled again using javac
work.java. I still get the answer of 'Final Result is 2'.
Now, I delete all the classes generated and compiled again using javac
work.java. This time, I get 'Final Result is 1'.
Does this mean that javac command is not reliable. I should use
NetBeans? (I am trying not to rely on IDE)
public class work{
public static void main(String args[]) {
test t1=new test() ;
t1.getResult() ;
test t2=new test() ;
System.out.println("Final Result is " + t2.getResult() ) ;
}
}
*****************************************************************************
public class test {
public test() {
}
int getResult() {
result r = new result() ;
r.setCount() ;
return r.getCount() ;
}
}
*****************************************************************************
public class result {
static int count ;
public result() {
}
void setCount() {
count++ ;
}
int getCount() {
return count ;
}
}
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---