Java Basic Program Practice Test-7

What will be the output of the following java code?

public class Test {

private static Test obj = null;

private Test() {

System.out.println("sany");

}

public static Test getObject() {

obj = new Test();

return obj;

}

public static void main(String[] args) {

Test a1 = Test.getObject();

Test a2 = Test.getObject();

}

}

What will be the output of the following java code?

public class Test {

static int i = 56;

static {

i = 45;

}

public static void main(String[] args) {

System.out.println(i);

}

}

What will be the output of the following java code?

public class Test {

public static void main(String[] args) {

String s = "Java";

s.concat("Programming");

System.out.println(s);

}

}

What will be the output of the following java code?

public class Test {

public static void main(String[] args) {

String s1 = new String("Java");

s1 = "Developer";

System.out.println(s1);

}

}

What will be the output of the following java code?

public class Test {

private static int i = 0;

void Test() {

i = 20;

}

Test(int a) {

i = a;

}

public static void main(String[] args) {

Test test = new Test();

System.out.println(i);

}

}