Question: QUESTION 3 Analyze the following code. public class static int n = 2 ; public static void main ( String [ ] args ) {

QUESTION 3
Analyze the following code.
public class
static int n=2;
public static void main(String[] args){
xMethod(n);
System.out.println("n is "+ n);
}
static void xMethod(int n){
n++;
}
}
A. n should not be declared static.
B. n can not be assigned as argument of XMethod
C. The code prints n is 1.
D. The code prints n is 2.
E. The code prints n is 3.
QUESTION 4
What is the printout of the second println statement in the main method? public class Foo {
static int i;
static int s;
public static void main(String[] args){
Foo f1= new Foo();
System.out.println("f1.i is "+ f1.i +" f1.s is "+ f1.s);
Foo f2= new Foo();
System.out.println("f2.i is "+ f2.i +" f2.s is "+ f2.s);
Foo f3= new Foo();
System.out.println("f3.i is "+ f3.i +" f3.s is "+ f3.s);
}
public
i++;
s++;
}
}
A.f2.i is 1f2.s is 1
B.f2.i is 1f2.s is 2
C.f2.i is 2f2.s is 2
D.f2.i is 2f2.s is 1
 QUESTION 3 Analyze the following code. public class static int n=2;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!