Inheritance question

Can I ask a simple question, if I may?

Suppose I have a Class A like this:

public class A {

private static int x;

public static void process( ){

//do some processing to x.

}

public static void process1( ){

//do some processing to x.

}

public static void process2( ){

//do some processing to x.

}

....

....

....

}

Then I have class B

public class B extends A {

private static int y;

}

the questions is, when I call B.process(), B.process1(), B.process2(), ....how can i get it process number y instead of number x in its super class?

[671 byte] By [01010a] at [2007-10-3 9:28:04]
# 1
> the questions is, when I call B.process(),> B.process1(), B.process2(), ....how can i get it> process number y instead of number x in its super> class?From Sun's Java Tutorial: http://java.sun.com/docs/books/tutorial/java/IandI/super.html
hungyee98a at 2007-7-15 4:42:25 > top of Java-index,Java Essentials,Java Programming...
# 2

yes i guess if u name both variables the same say x

and in class A

u used a get function to get x

and then in class B

u override this get function with another function also to get x but in this case u get the x of class B

and then in each time u want to use x u use the get function

the result will be as u desire

but i am not sure that u can inherit a static field or method

el3oriana at 2007-7-15 4:42:25 > top of Java-index,Java Essentials,Java Programming...
# 3
To the OP: Sorry about my earlier post - didn't read your original question correctly. Calling super() won't help in this particular case because that will only operate on the super class's x variable,and not on the subclass.
hungyee98a at 2007-7-15 4:42:25 > top of Java-index,Java Essentials,Java Programming...
# 4
but still when you call B.process(), it will call A.process(), in which the x of Class A get processed.
01010a at 2007-7-15 4:42:25 > top of Java-index,Java Essentials,Java Programming...
# 5

no if u each time referenced x with getX function which is overriden in Class B and x is also found in Bwhen u use method B.process it will use x of B

Class A

{

static private int x

static public int getX()

{

return x

}

static process ()

{//instead of x use getX()

}

}

Class B extends A

{

static private x;

static public int getX( )

{

return x;

}

}

B.process will use x of B

el3oriana at 2007-7-15 4:42:25 > top of Java-index,Java Essentials,Java Programming...
# 6

Probably the easiest solution would be to get rid of variable y in class B and just use x.

class B extends A {

public B(int n) {

x = n;

}

}

public class Test {

public static void main(String[] args) {

B obj = new B(10);

obj.process();

}

}

floundera at 2007-7-15 4:42:25 > top of Java-index,Java Essentials,Java Programming...