Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sql All In One For Dummies 7 Books In One

Authors: Allen G Taylor ,Richard Blum

4th Edition

1394242298, 978-1394242290

More Books

Students also viewed these Databases questions

Question

2. In what way can we say that method affects the result we get?

Answered: 1 week ago

Question

What are the classifications of Bank?

Answered: 1 week ago