MSD Java Test
What is the output of below program?
public class Example {
public static void main(String[] args) {
StringBuffer sb = "Hello";
sb.append("world");
System.out.println(sb.tostring());
}
}
What is the output of below program?
class myclass {
public static void main(String[] args) {
for(int I = 0; true; i++) {
System.out.println("Hello");
break;
}
}
}
What is the output of below program?
class class1 {
public static void main(String args[]) {
System.out.println(fun());
}
static int fun() {
static int x= 0;
return ++x;
}
}
What is the output of below program?
package pkg;
class Base {
public void Print() {
System.out.println("Base");
}
}
class Derived extends Base {
public void Print() {
System.out.println("Derived");
}
}
class Main{
public static void display( Base o ) {
o.Print();
}
public static void main(String[] args) {
Base x = new Base();
Base y = new Derived();
Derived z = new Derived();
display (x);
display (y);
display (z);
}
}
What is the output of below program?
public class test{
public static void main(String args[]){
int I = 0;
I = i++ + I;
System.out.println(“I = ” +i);
}
}
What is the output of below program?
public class myclass {
public static int foo(int a, String s){
s = “Yellow”;
a=a+2;
return a;
}
public static void bar(){
int a=3;
String s = “Blue”;
a = foo(a,s);
System.out.println(“a=”+a+” s=”+s);
}
public static void main(String args[]){
bar();
}
}
What is the output of below program?
class class1 {
public static void main(String args[])
{
int sum = 0;
for (int I = 0, j = 0; I < 5 & j < 5; ++i, j = I + 1)
sum += I;
System.out.println(sum);
}
}
What is the output of below program?
class Output
{
public static void main(String args[])
{
final int a=10,b=20;
while(a<b) {
System.out.println("Hello");
}
System.out.println(" World");
}
}
What is the output of below program?
class First {
public First() { System.out.print("a"); }
}
class Second extends First {
public Second() { System.out.print("b"); }
}
class Third extends Second {
public Third() { System.out.print("c"); }
}
public class MainClass {
public static void main(String[] args) {
Third c = new Third();
}
}
What is the output of below program?
public class ArrayParam2 {
public void updateParam( double[] x ) {
x[0] = 10.5;
}
public static void main(String[] args) {
double[] a = {2.5, 5.0};
ArrayParam2 obj = new ArrayParam2();
obj.updateParam( a );
for (int I = 0; I < a.length; i++)
System.out.print( a[i] );
}
}
What is the output of below program?
public class priorityQueue {
public static void main(String[] args)
{
PriorityQueue<Integer> queue = new PriorityQueue<>();
queue.add(11);
queue.add(10);
queue.add(22);
queue.add(5);
queue.add(12);
queue.add(2);
while (queue.isEmpty() == false)
System.out.printf("%d ", queue.remove());
System.out.println("\n");
}
}
What is the output of below program?
public class test {
static {
System.out.printf("%d", 1);
}
static {
System.out.printf("%d", 2);
}
static {
System.out.printf("%d", 3);
}
private static int myMethod() {
return 4;
}
private int fun
return 5;
}
public static void main(String[] args) {
System.out.printf("%d", (new javaclass()).fun
}
}