code:
import java.io.*;
class cl{
public static int a;
public static void f(int x){
a = x;
}
}
public class cl1 {
public static void main (String[] args) {
// create an instance of the class.
cl ob = new cl();
System.out.println(ob.a);
// calling an instance method in the class 'Foo'.
ob.f(7);
System.out.println(ob.a);
cl.f(9);
System.out.println(cl.a);
System.out.println(ob.a);
cl ob1 = new cl();
System.out.println(ob1.a);
}
}
output:
import java.io.*;
class cl{
public static int a;
public static void f(int x){
a = x;
}
}
public class cl1 {
public static void main (String[] args) {
// create an instance of the class.
cl ob = new cl();
System.out.println(ob.a);
// calling an instance method in the class 'Foo'.
ob.f(7);
System.out.println(ob.a);
cl.f(9);
System.out.println(cl.a);
System.out.println(ob.a);
cl ob1 = new cl();
System.out.println(ob1.a);
}
}
output:
$javac cl1.java $java -Xmx128M -Xms16M cl1 0 7 9 9 9
No comments:
Post a Comment