Given:
public class ScopeTest {
int z;
public static void main(String[] args){
ScopeTest myScope = new ScopeTest();
int z = 6;
System.out.println(z);
myScope.doStuff();
System.out.println(z);
System.out.println(myScope.z);
}
void doStuff() {
int z = 5;
doStuff2();
System.out.println(z);
}
void doStuff2() {
z=4;
}
What is the result?
A.
6 5 6 4
B.
6 5 5 4
C.
6 5 6 6
D.
6 5 6 5
Explanation:
Within main z is assigned 6. z is printed. Output: 6
Within doStuff z is assigned 5.DoStuff2 locally sets z to 4 (but MyScope.z is set to 4), but in Dostuff z
is still 5. z is printed. Output: 5
Again z is printed within main (with local z set to 6). Output: 6
Finally MyScope.z is printed. MyScope.z has been set to 4 within doStuff2(). Output: 4
Letter A
Usually posts some pretty interesting stuff like this. If youre new to this site.
Sites of interest we’ve a link to.
check beneath, are some completely unrelated internet sites to ours, having said that, they may be most trustworthy sources that we use
Sites of interest we’ve a link to
we came across a cool internet site which you may well take pleasure in. Take a appear in the event you want
always a significant fan of linking to bloggers that I like but do not get quite a bit of link adore from
we came across a cool web-site that you just may possibly enjoy. Take a search when you want
Sites of interest we have a link to
we like to honor many other net web-sites on the net, even though they arent linked to us, by linking to them. Beneath are some webpages worth checking out
one of our visitors a short while ago proposed the following website
very few internet websites that come about to become in depth beneath, from our point of view are undoubtedly properly really worth checking out
Sites of interest we’ve a link to