Hi,

On 18 Dez., 08:29, Te <[email protected]> wrote:
> 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'.
You have all your classes in separate files called work.java test.java
and result.java.
Having all in one work.java results in a compilation error with Java
1.6 and 1.5.

You compiled every file with "javac work.java", "javac test.java" and
"javac result.java"
After this you changed in result.java the code and recompiled
work.java.

So the class-file result.class is not changed to reflect your changes
of count-variable,
because you have not orderd javac to do it.
Therefore is e.g. and ant-buildfile which checks if anything has to be
recompiled.
An IDE would do this job for you.

HTH
Ewald

>
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to