What is the result?

Given:
<code>
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;
}
</code>
What is the result?

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



Leave a Reply 13

Your email address will not be published. Required fields are marked *


symphony

symphony

Letter A

Google

Google

Usually posts some pretty interesting stuff like this. If youre new to this site.

Google

Google

Sites of interest we’ve a link to.

SEO services in Lahore

SEO services in Lahore

check beneath, are some completely unrelated internet sites to ours, having said that, they may be most trustworthy sources that we use

read more

read more

Sites of interest we’ve a link to

how to make your own app

how to make your own app

we came across a cool internet site which you may well take pleasure in. Take a appear in the event you want

chi garage doors

chi garage doors

always a significant fan of linking to bloggers that I like but do not get quite a bit of link adore from

usmc combat techniques

usmc combat techniques

we came across a cool web-site that you just may possibly enjoy. Take a search when you want

app maker free

app maker free

Sites of interest we have a link to

bonos apuestas

bonos apuestas

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

UPC Shop Innsbruck Hall

UPC Shop Innsbruck Hall

very few internet websites that come about to become in depth beneath, from our point of view are undoubtedly properly really worth checking out

iphone 5s

iphone 5s

Sites of interest we’ve a link to