Q 1 : What is the output?
import java.util.*; public class Test1{ public static void main(String a[]){ Set s = new TreeSet(); s.add(new Person(20)); s.add(new Person(10)); System.out.println(s); } } class Person{ Person(int i){} }
Choose the one below:
- 10 20
- ClassCastException
- Compiler Error
- Compiler Error
Q 2 : What is the output?
import java.util.*; public class Test2{ public static void main(String a[]){ Map s = new Hashtable(); s.put(null,null); System.out.println(s); } }
Choose the one below:
- [null = null]
- NullPointerException
- null
- []
Q 3 : What is the output?
import java.util.*; public class Test3{ public static void main(String a[]){ Map s = new WeakHashMap(10); s.put(null,null); System.out.println(s); } }
Choose the one below:
- [null = null]
- NullPointerException
- null
- []
Q 4 : What is the output?
import java.util.*; public class Test4{ public static void main(String a[]){ Map s = new LinkedHashMap(); s.put("1","one"); s.put("3","three"); s.put("2","two"); System.out.println(s); } }
Choose the one below:
- [1=one,3=three,2=two]
- NullPointerException
- [1=one,2=two,3=three]
- []
Q 5 : What is the output?
import java.util.*; public class Test5{ public static void main(String a[]){ Map s = new HashMap(); s.put("1","one"); s.put("3","three"); s.put("2","two"); System.out.println(s); } }
Choose the one below:
- [1=one,3=three,2=two]
- [3=three,2=two,1=one]
- cannot predict the order
- []
Q 6 : What is the output?
public class Test6{ public static void method(float f){ System.out.println("Float"); } public static void method(double f){ System.out.println("Double"); } public static void main(String a[]){ float f1 = 2.0f; float f2 = 2.0f; method(1.0); method(1.0f); method(1.0f*2.0f); method(1.0f*2.0); method(f1*f2); } }
Choose the one below:
- Double Double Double Double Double
- Float Float Float Float Float
- Double Float Float Double Float
- Double Float Float Double Double
Q 7 : What is the output?
public class Test7{ public static void method(byte b){ System.out.println("Byte"); } public static void method(int i){ System.out.println("Int"); } public static void main(String a[]){ byte b = 1; method(1); method(128); method((byte)128); method(b); } }
Choose the one below:
- Byte Int Int Byte
- Byte Int Int Byte
- Byte Int Byte Byte
- Int Int Byte Byte
Q 8 : Which of the following are correct?
public class Test8{ public static void main(String a[]){ byte b = 1; char c = 2; short s = 3; int i = 4; c = b; // 1 s = b; // 2 i = b; //3 s = c * b; //4 } }
Choose the one below:
- Error at mark 1
- Error at mark 2
- Error at mark 3
- Error at mark 4
Q 9 : Which of the following are correct?
public class Test9{ public static void main(String a[]){ final byte b = 1; char c = 2; short s = 3; int i = 4; c = b; // 1 s = b; // 2 i = b; //3 s = c * b; //4 } }
Choose the one below:
- Error at mark 1
- Error at mark 2
- Error at mark 3
- Error at mark 4
Q 10 : What is output?
public class Test10{ public static void main(String a[]){ String s1 = "Sun"; String s2 = "Java"; s1.concat(s2); System.out.println(s1); } }
Choose the one below:
- Sun
- Java
- SunJava
- JavaSun
Q 11 : What is output?
public class Test11{ public static void main(String a[]){ Integer i1 = new Integer(127); Integer i2 = new Integer(127); Long l = new Long(127); System.out.println(i1 == i2); System.out.println(i1.equals(i2)); System.out.println(i1.equals(l)); } }
Choose the one below:
- false true true
- true true true
- false true false
- Compiler Error
Q 12 : What is output?
public class Test12{ public static void main(String a[]){ byte b = 100; Byte b1= new Byte(100); Byte b2 = new Byte(b); System.out.println(b1 == b2); System.out.println(b1.equals(b2)); } }
Choose the one below:
- false true
- true false
- true true
- Compiler Error
Q 13 : What is output?
public class Test13{ public static void method(String s){ System.out.println("String Version"); } public static void method(StringBuffer sb){ System.out.println("String Buffer Version"); } public static void main(String a[]){ method(null); } }
Choose the one below:
- String Version
- String Buffer Version
- Runtime Exception
- Compiler Error
Q 14 : What is output?
public class Test14{ static String s ="Instance"; public static void method(String s){ s+="Add"; } public static void main(String a[]){ Test14 t = new Test14(); s = "New Instance"; String s = "Local"; method(s); System.out.println(s); System.out.println(t.s); } }
Choose the one below:
- Local Instance
- Local New Instance
- Local Add New Instance
- Compiler Error
Q 15 : What is output?
public class Test15{ public static void method(StringBuffer sb){ sb.append(" Added"); sb = new StringBuffer("Hai"); } public static void main(String a[]){ StringBuffer sb = new StringBuffer("String Buffer"); method(sb); System.out.println(sb); } }
Choose the one below:
- String Buffer
- String Buffer Added
- Hai
- Compiler Error
Q 16 : What is output?
public class Test16{ public static void method(StringBuffer sb){ sb = new StringBuffer("Hai"); sb.append(" Added"); } public static void main(String a[]){ StringBuffer sb = new StringBuffer("String Buffer"); method(sb); System.out.println(sb); } }
Choose the one below:
- String Buffer
- String Buffer Added
- Hai
- Compiler Error
Q 17 : What is output?
import java.util.*; public class Test17{ public static void main(String a[]){ Map m = new Hashtable(10,0.75f); System.out.println(m.size()); } }
Choose the one below:
- 10
- 7
- cOMPILER eRROR
Q 18 : What is the default capacity of java.util.Hashtable?
- 10
- 16
- 11
- 20
Q 19 : What is the default capacity of java.util.HashMap?
- 10
- 16
- 11
- 20
Q 20 : Which of the following classes has synchronized methods?
- ArrayList
- Vector
- HashTable
- WeakHashMap
Q 21 : What is output?
public class Test21{ public static void main(String a[]){ String s1 = new String("Hai"); String s2 = "Hai"; String s3 = new String("Hai").intern(); System.out.println(s1 == s2); System.out.println(s1 == s3); System.out.println(s2 == s3); } }
Choose the one below:
- false false true
- true false true
- false false false
- false true true
Q 22 : What is output?
public class Test22{ public static void main(String a[]){ String s1 = "SunMicroSystems"; System.out.println(s1.substring(0)); System.out.println(s1.substring(1,4)); System.out.println(s1.substring(8)); } }
Choose the one below:
- SunMicrosystems sun oSystem
- SunMicrosystems unM Systems
- StringIndexOutOfBoundsException
- None Of the above
Q 23 : What is output?
public class Test23{ public static void main(String a[]){ String s1 = "Sun"; System.out.println(s1.substring(5)); } }
Choose the one below:
- -1
- 0
- StringIndexOutOfBoundsException
- ArrayIndexOutOfBoundsException
Q 24 : Which of the following are static methods in java.lang.String class?
- valueOf
- length
- indexOf
- All the above.
Q 25 : What is output?
public class Test25{ public static void main(String a[]){ StringBuffer sb = new StringBuffer(8); sb.append("TestString"); System.out.println(sb.capacity()); System.out.println(sb.length()); } }
Choose the one below:
- 8 10
- 10 10
- 18 10
- 18 18
Answers
Q 1 : 2 is correct. ClassCastException.
Q 2 : 2 is correct. NullPointerException.
Q 3 : 1 is correct. [null = null].
Q 4 : 1 is correct. [1=one,3=three,2=two].
Q 5 : 3 is correct. cannot predict the order.
Q 6 : 3 is correct. Double Float Float Double Float.
Q 7 : 4 is correct. Int Int Byte Byte.
Q 8 : 1 is correct. Error at mark 1.
4 is correct. Error at mark 4.
Q 9 : 4 is correct. Error at mark 4.
Q 10 : 1 is correct. Sun.
Q 11 : 3 is correct. false true false.
Q 12 : 4 is correct. Compiler Error.
Q 13 : 4 is correct. Compiler Error.
Q 14 : 2 is correct. Local New Instance.
Q 15 : 2 is correct. String Buffer Added.
Q 16 : 1 is correct. String Buffer.
Q 17 : 1 is correct. 0.
Q 18 : 3 is correct. 11.
Q 19 : 2 is correct. 16.
Q 20 : 2 is correct. Vector.
3 is correct. HashTable.
Q 21 : 1 is correct. false false true.
Q 22 : 2 is correct. SunMicrosystems unM Systems.
Q 23 : 3 is correct. StringIndexOutOfBoundsException.
Q 24 : 1 is correct. valueOf.
Q 25 : 3 is correct. 18 10.