Online Test

  • Facebook
  • Google
  • LinkedIn
  • Twitter
Question: 1
//Which is the correct option of this programs?


class Fruit {
	public int i = 10;

	public Fruit() {
		i = 12;
	}

	public String toString() {
		return "Test" + i;
	}
}

public class MainApp {
	public static void main(String[] args) {
		HashSet<Fruit> hs = new HashSet();
		hs.add(new Fruit());
		hs.add(new Fruit());
		for (Fruit f : hs) {
			System.out.println(f);
		}

	}
}
Test12Test12
Test12
12
1212

Question: 2
//Which is the correct option of this programs?

package test;

public class MainApp {
	public static void main(String[] srgs) {
		try {
			checkException();
			System.out.print("A");
		} catch (RuntimeException ex) {
			System.out.print("B");
		} catch (Exception ex) {
			System.out.print("C");
		} finally {
			System.out.print("D");
		}
		System.out.print("10");
	}

	public static void checkException() {
		throw new RuntimeException();
	}
}
BD10
BD
BCD
BCD10

Question: 3
Which of the following is incorrect statement about interface?
Interfaces specifies what class must do but not how it does.
Interfaces are specified public if they are to be accessed by any code in the program.
All variables in interface are implicitly final and static.
All variables are static and methods are public if interface is defined pubic.

Question: 4
//Which of the following option is correct for below example ?

package com.javatutsworld.test;

public class MainApp {
	private MainApp(int w) { // line 3
		System.out.print(w);
	}

	public static MainApp() { // line 6
		System.out.print(10);
	}

	public static void main(String args[]) {
		MainApp obj = new MainApp(50);
	}
}
Won't compile because of line (3), constructor can't be private
10 50
50
Won't compile because of line (6), constructor can't be static

Question: 5
Which of the following is not a wrapper class?
Character
Vector
Boolean
Integer

Question: 6
Which of the following may be part of a class definition?
instance variables
instance methods
constructors
all of the above

Question: 7
//What is the output of this program?

package com.javatutsworld;

import java.util.Arrays;

class MainApp {
	public static void main(String args[]) {
		int array[] = new int[4];
		for (int i = 4; i > 0; i--) {
			array[4 - i] = i;
		}
		Arrays.sort(array);
		for (int i = 0; i < 4; ++i) {
			System.out.print(array[i]);
		}
	}
}
1234
4321
123
321

Question: 8
//What will be the correct option for the following program

package com.javatutsworld.test;

public class MainApp {
	public static void main(String[] args) {
		Test t = new Test();
	}
}

class Test {
	int a;

	void Test() {
		System.out.println("ABC const");
	}
}
Compile time error.
Run time error
ABC const
Nothing will print

Question: 9
What will be the output of the program? 

package javatutsworld.com;

class MainApp {

	public static void main(String args[]) {
		int x = 1, y = 6;
		while (y--) {
			x++;

		}
		System.out.println("x = " + x + " y = " + y);
	}

}
x = 6 y = 0
x = 7 y = 0
x = 6 y = -1
Compilation fails.

Question: 10
//Which options are true ?

class MainApp {

	static void test() {

		/* body code here */
	}

	void test1() {

		/* body code here */
	}

}
MainApp.test1() is a valid and test() method can directly call to method test1().
MainApp.test() is a valid and test1() method can directly call to method test().
Both of the above
None of the above

      Advertisements