Re: What happens to x
- From: "Richard Reynolds" <richiereynolds@xxxxxxxxxxxx>
- Date: Sun, 29 Apr 2007 20:35:10 GMT
"Ravi" <ra.ravi.rav@xxxxxxxxx> wrote in message
news:1177876365.913340.26180@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
what will be the effect of the following code on variable x, and why:
class Sup {
int x=10;
void set(int a) {
x = a;
}
}
class Sub {
private int x;
}
class Demo {
public static void main(String args[]) {
Sub s1 = new Sub();
s1.set(2)
}
}
did you mean to say "class Sub extends Sup" and "protected void set"?
if so then when you create Sub with "new", x will be 10, after the call to
set it will be 2
.
- References:
- What happens to x
- From: Ravi
- What happens to x
- Prev by Date: HTTP/1.1 500 Internal Server Error
- Next by Date: moving on to jslider...
- Previous by thread: What happens to x
- Next by thread: HTTP/1.1 500 Internal Server Error
- Index(es):