What is the output of the following program explain explain


1. Indicate whether each of the following statements is true or false:

Local variables always retain their values from one call of a method to the next.
There is only one copy of each class variable that is shared by all instances of the class.
The reserved word this can be used in class methods.
Private instance variables can accessed in any instance method in the same class.
Public methods can be can be accessed by any method in the same program.

2. What is the output of the following program? Explain.
public class Test
{
public static void main(String[] args)
{
int i = 1;
StringBuilder s = new StringBuilder("s");
String t = "t";

someMethod(i, s, t);
System.out.println("i = " + i);
System.out.println("s = " + s);
System.out.println("t = " + t);
}
private static void someMethod(int i, StringBuilder s,
String t)
{
i++;
s.append("s");
t += "t";
}
}

3. Is the following class immutable? Explain
class Class1
{
private int[] array = new int[10];

public int[] getArray()
{
return array;
}
}

4. Will the following class compile?
class Class2
{
private void method()
{
}

public static void main(String[] args)
{
method();
}
}
If not, explain why and correct it so it will compile.

5. Explain the meaning of the reserved word this and why it is necessary in the class below. Will the class compile without using this?
class Class3
{
private int x;

public Class3(int x)
{
this.x = x;
}
}

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: What is the output of the following program explain explain
Reference No:- TGS01090646

Expected delivery within 24 Hours