Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Suppose that the class F is defined in (a). Let f be an instance of F. Which of the statements in (b) are correct?

1) Suppose that the class F is defined in (a). Let f be an instance of F.

Which of the statements in (b) are correct?

(a)

public class F {

int i;

static String s;

void imethod() {

}

static void smethod() {

}

}

(b)

System.out.println(f.i);

System.out.println(f.s);

f.imethod();

f.smethod();

System.out.println(F.i);

System.out.println(F.s);

F.imethod();

F.smethod();

2) Show the output of the following code:

(a)

public class Test {

public static void main(String[] args) {

int[] a = {1, 2};

swap(a[0], a[1]);

System.out.println("a[1] = " + a[1]

+ " a[0] = " + a[0]);

}

public static void swap(int n1, int n2) {

int temp = n1;

n1 = n2;

n2 = temp;

}

}

(b)

public class Test {

public static void main(String[] args) {

int[] a = {1, 2};

swap(a);

System.out.println("a[1] = " + a[1]

+ " a[0] = " + a[0]);

}

public static void swap(int[] a) {

int temp = a[0];

a[0] = a[1];

a[1] = temp;

}

}

(c)

public class Test {

public static void main(String[] args) {

T t = new T();

swap(t);

System.out.println("e1 = " + t.e1

+ " e2 = " + t.e2);

}

public static void swap(T t) {

int temp = t.e1;

t.e1 = t.e2;

t.e2 = temp;

}

}

class T {

int e1 = 1;

int e2 = 2;

}

(d)

public class Test {

public static void main(String[] args) {

T t1 = new T();

T t2 = new T();

System.out.println("t1's i = " +

t1.i + " and j = " + t1.j);

System.out.println("t2's i = " +

t2.i + " and j = " + t2.j);

}

}

class T {

static int i = 1;

int j = 1;

T() {

i++;

j = 1;

}

}

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

Step: 3

blur-text-image

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago