Static data sharing

I always thought that

a object cannot be modified unless u have explicit referece(authority to modify)

but the code below allows me to modify the property effecting all the objects ob the base class i doubt(Though i have no rights to say so)

it obeys OOPs priciples

the code for r4eference

please let me know

class b

{

public static int x=25;

public b()

{

System.out.println("in the super");

}

public void show ()

{

System.out.println(x);

}

}

public class a extends b

{

public a()

{

super();

super.x=36;

super.show();

}

public static void main(String args[])

{

a x = new a();

b b1 = new b();

b1.show();

}

}

[806 byte] By [madanvishnua] at [2007-9-28 6:59:29]
# 1

> class b

> {

> public static int x=25;

[...]

> }

You declared x as public so you gave everyone the authority to access it.

private int x; // access only to the owner class

protected int x; // access to the owner class and any subclass

public int x;// access to everyone

ceccsa at 2007-7-9 18:10:14 > top of Java-index,Other Topics,Java Community Process (JCP) Program...