SlideShare a Scribd company logo
Questions no -1 <br />What is the output for the below code ?<br />class A implements Runnable{<br />public void run(){<br />System.out.println(Thread.currentThread().getName());<br />}   <br />}<br />public class Test {<br />public static void main(String... args) {<br />A a = new A();<br />Thread t = new Thread(a);<br />Thread t1 = new Thread(a);<br />t.setName(quot;
tquot;
);<br />t1.setName(quot;
t1quot;
);<br />t.setPriority(10);<br />t1.setPriority(-3);<br />t.start();<br />t1.start();<br />}<br />}<br />Options are A.t t1B.t1 tC.t tD.Compilation succeed but Runtime ExceptionAnswer :D is the correct answer. <br />Thread priorities are set using a positive integer, usually between 1 and 10. t1.setPriority(-3); throws java.lang.IllegalArgumentException. <br />Questions no -2 <br />What is the output for the below code ?<br />class A implements Runnable{<br />public void run(){<br />System.out.println(Thread.currentThread().getName());<br />}   <br />}<br />1. public class Test {<br />2.public static void main(String... args) {<br />3.A a = new A();<br />4.Thread t = new Thread(a);<br />5.t.setName(quot;
goodquot;
);<br />6.t.start();<br />7.}<br />8. }<br />Options are A.goodB.nullC.Compilation fails with an error at line 5D.Compilation succeed but Runtime ExceptionAnswer :A is the correct answer. <br />Thread.currentThread().getName() return name of the current thread. <br />Questions no -3 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String[] args) {<br />Boolean expr = true;<br />if (expr) {<br />System.out.println(quot;
truequot;
);<br />} else {<br />System.out.println(quot;
falsequot;
);<br />}<br />}<br />}<br />options<br />A)true<br />B)Compile Error - can't use Boolean object in if().<br />C)false<br />D)Compile Properly but Runtime Exception.<br />Correct answer is : A<br />Explanations : In the if statement, condition can be Boolean object in jdk1.5 and jdk1.6.<br />In the previous version only boolean is allowed.<br />Questions no -4 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String[] args) {<br />List<Integer> list = new ArrayList<Integer>(); <br />list.add(0, 59);<br />int total = list.get(0);<br />System.out.println(total);<br />}<br />}<br />options<br />A)59<br />B)Compile time error, because you have to do int total = ((Integer)(list.get(0))).intValue();<br />C)Compile time error, because can't add primitive type in List.<br />D)Compile Properly but Runtime Exception.<br />Correct answer is : A<br />Explanations :Manual conversion between primitive types (such as an int) and wrapper classes <br />(such as Integer) is necessary when adding a primitive data type to a collection in jdk1.4 but<br />The new autoboxing/unboxing feature eliminates this manual conversion in jdk 1.5 and jdk 1.6.<br />Questions no -3 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String[] args) {<br />Integer i = null;<br />int j = i;<br />System.out.println(j);<br />}<br />}<br />options<br />A)0<br />B)Compile with error <br />C)null<br />D)NullPointerException<br />Correct answer is : D<br />Explanations :An Integer expression can have a null value. If your program tries to autounbox null, it will throw a NullPointerException.<br />Questions no -4 <br />What is the output for the below code ?<br />public class Outer {<br />private int a = 7;<br />   <br />   class Inner {<br />      public void displayValue() {<br />         System.out.println(quot;
Value of a is quot;
 + a);<br />      }<br />   }<br />}<br />public class Test {<br />public static void main(String... args) throws Exception {<br />Outer mo = new Outer();     <br />  Outer.Inner inner = mo.new Inner();<br />  inner.displayValue();<br />}<br />}<br />options<br />A)Value of a is 7<br />B)Compile Error - not able to access private member.<br />C)Runtime Exception<br />D)Value of a is 8<br />Correct answer is : A<br />Explanations : An inner class instance can never stand alone without a direct relationship to an instance of the outer class.<br />you can access the inner class is through a live instance of the outer class.<br />Inner class can access private member of the outer class.<br />Questions no -5 <br />What is the output for the below code ?<br />public class B {<br />public String getCountryName(){<br />return quot;
USAquot;
;<br />}<br />public StringBuffer getCountryName(){<br />StringBuffer sb = new StringBuffer();<br />sb.append(quot;
UKquot;
);<br />return sb;<br />}<br />public static void main(String[] args){<br />B b = new B();<br />System.out.println(b.getCountryName().toString());<br />}<br />}<br />options<br />A)Compile with error<br />B)USA<br />C)UK<br />D) Runtime Exception<br />Correct answer is : A<br />Explanations : You cannot have two methods in the same class with signatures that only differ by return type.<br />Questions no -6<br />What is the output for the below code ?<br />public class C {<br />}<br />public class D extends C{<br />}<br />public class A {<br />public C getOBJ(){<br />System.out.println(quot;
class A - return Cquot;
);<br />return new C();<br />}<br />}<br />public class B extends A{<br />public D getOBJ(){<br />System.out.println(quot;
class B - return Dquot;
);<br />return new D();<br />}<br />}<br />public class Test {<br />public static void main(String... args) {<br />     A a = new B();<br />     a.getOBJ();<br />     }<br />}<br />options<br />A)Compile with error - Not allowed to override the return type of a method with a subtype of the original type.<br />B)class A - return C<br />C)class B - return D<br />D) Runtime Exception<br />Correct answer is : C<br />Explanations : From J2SE 5.0 onwards. You are now allowed to override the return type of a method with a subtype of the original type.<br />Questions no -7<br />What is the output for the below code ?<br />public class A {<br />public String getName() throws ArrayIndexOutOfBoundsException{<br />return quot;
Name-Aquot;
;<br />}<br />}<br />public class C extends A{<br />public String getName() throws Exception{<br />return quot;
Name-Cquot;
;<br />}<br />}<br />public class Test {<br />public static void main(String... args) {<br />A a = new C();<br />a.getName();<br />}<br />}<br />options<br />A)Compile with error<br />B)Name-A<br />C)Name-C<br />D)Runtime Exception<br />Correct answer is : A<br />Explanations : Exception Exception is not compatible with throws clause in A.getName().<br />Overridden method should throw only same or sub class of the exception thrown by super class method.<br />Questions no -8 <br />What is the output for the below code ?<br />import java.util.regex.Matcher;<br />import java.util.regex.Pattern;<br />public class Test {<br />public static void main(String... args) {<br />            <br />Pattern p = Pattern.compile(quot;
a*bquot;
);<br />Matcher m = p.matcher(quot;
bquot;
);<br />boolean b = m.matches();<br />System.out.println(b);<br />}<br />}<br />options<br />A)true<br />B)Compile Error<br />C)false<br />D)b<br />Correct answer is : A<br />Explanations : a*b means quot;
aquot;
 may present zero or more time and quot;
bquot;
 should be present once.<br />Questions no -9 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br />            <br />String input = quot;
1 fish 2 fish red fish blue fishquot;
;<br />Scanner s = new Scanner(input).useDelimiter(quot;
s*fishs*quot;
);<br />System.out.println(s.nextInt());<br />System.out.println(s.nextInt());<br />System.out.println(s.next());<br />System.out.println(s.next());<br />s.close(); <br />}<br />}<br />options<br />A)1 2 red blue<br />B)Compile Error - because Scanner is not defind in java.<br />C)1 fish 2 fish red fish blue fish<br />D)1 fish 2 fish red blue fish<br />Correct answer is : A<br />Explanations : java.util.Scanner is a simple text scanner which can parse primitive types and strings using regular expressions.<br />Questions no -10 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br />            <br />Pattern p = Pattern.compile(quot;
a{3}b?c*quot;
);<br />Matcher m = p.matcher(quot;
aaabquot;
);<br />boolean b = m.matches();<br />System.out.println(b);<br />}<br />}<br />options<br />A)true<br />B)Compile Error <br />C)false<br />D)NullPointerException<br />Correct answer is : A<br />Explanations :<br />X?  X, once or not at all <br />X*  X, zero or more times <br />X+  X, one or more times <br />X{n}  X, exactly n times <br />X{n,}  X, at least n times <br />X{n,m}  X, at least n but not more than m times<br />Questions no -11 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br />            <br />Pattern p = Pattern.compile(quot;
a{1,3}b?c*quot;
);<br />Matcher m = p.matcher(quot;
aaabquot;
);<br />boolean b = m.matches();<br />System.out.println(b);<br />}<br />}<br />options<br />A)true<br />B)Compile Error <br />C)false<br />D)NullPointerException<br />Correct answer is : A<br />Explanations :<br />X?  X, once or not at all <br />X*  X, zero or more times <br />X+  X, one or more times <br />X{n}  X, exactly n times <br />X{n,}  X, at least n times <br />X{n,m}  X, at least n but not more than m times<br />Questions no -12 <br />What is the output for the below code ?<br />public class A {<br />public A() {<br />        System.out.println(quot;
Aquot;
);<br />    }<br />}<br />public class B extends A implements Serializable {<br />public B() {<br />        System.out.println(quot;
Bquot;
);<br />    }<br />}<br />public class Test {<br />public static void main(String... args) throws Exception {<br />B b = new B();<br />       <br />        ObjectOutputStream save = new ObjectOutputStream(new FileOutputStream(quot;
datafilequot;
));<br />        save.writeObject(b); <br />        save.flush(); <br />        <br />        ObjectInputStream restore = new ObjectInputStream(new FileInputStream(quot;
datafilequot;
));<br />        B z = (B) restore.readObject();<br />        <br />}<br />}<br />options<br />A)A B A<br />B)A B A B<br />C)B B<br />D)A B<br />Correct answer is : A<br />Explanations :On the time of deserialization , the Serializable object not create new object. So constructor of class B does not called. <br />A is not Serializable object so constructor is called.<br />Questions no -13 <br />What is the output for the below code ?<br />public class A {}<br />public class B implements Serializable  {<br />A a = new A();<br />public static void main(String... args){<br />B b = new B();<br />try{<br />FileOutputStream fs = new FileOutputStream(quot;
b.serquot;
);<br />ObjectOutputStream os = new ObjectOutputStream(fs);<br />os.writeObject(b);<br />os.close();<br />}catch(Exception e){<br />e.printStackTrace();<br />}<br />}<br />}<br />options<br />A)Compilation Fail<br />B)java.io.NotSerializableException:  Because class A is not Serializable.<br />C)Run properly<br />D)Compilation Fail :  Because class A is not Serializable.<br />Correct answer is : B<br />Explanations :It throws java.io.NotSerializableException:A  Because class A is not Serializable.<br />When JVM tries to serialize object B it will try to serialize A also because (A a = new A()) is instance variable of Class B.<br />So thows NotSerializableException.<br />Questions no -14 <br />What is the output for the below code running in the same JVM?<br />public class A implements Serializable {<br />transient int a = 7;<br />  static int b = 9;<br />}<br />public class B implements Serializable  {<br />public static void main(String... args){<br />A a = new A();<br />try {<br />      ObjectOutputStream os = new ObjectOutputStream(<br />         new FileOutputStream(quot;
test.serquot;
));<br />      os.writeObject(a);  <br />      os. close();<br />      System.out.print( + + a.b + quot;
 quot;
);<br />      ObjectInputStream is = new ObjectInputStream(new FileInputStream(quot;
test.serquot;
));<br />      A s2 = (A)is.readObject();<br />      is.close();<br />      System.out.println(s2.a + quot;
 quot;
 + s2.b);<br />    } catch (Exception x) <br />    {<br />    x.printStackTrace();<br />    }<br />}<br />}<br />options<br />A)9 0 9<br />B)9 7 9<br />C)0 0 0<br />D)0 7 0<br />Correct answer is : A<br />Explanations :transient variables are not serialized when an object is serialized.<br />In the case of static variable you can get the values in the same JVM. <br />Questions no -15 <br />What is the output for the below code ?<br />public enum Test {<br />BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45);<br />private int hh;<br />private int mm;<br />Test(int hh, int mm) {<br />assert (hh >= 0 && hh <= 23) : quot;
Illegal hour.quot;
;<br />assert (mm >= 0 && mm <= 59) : quot;
Illegal mins.quot;
;<br />this.hh = hh;<br />this.mm = mm;<br />}<br />public int getHour() {<br />return hh;<br />}<br />public int getMins() {<br />return mm;<br />}<br />public static void main(String args[]){<br />Test t =  new BREAKFAST;<br />System.out.println(t.getHour() +quot;
:quot;
+t.getMins());<br />}<br />}<br />options<br />A)7:30<br />B)Compile Error - an enum cannot be instantiated using the new operator.<br />C)12:50<br />D)19:45<br />Correct answer is : B<br />Explanations : As an enum cannot be instantiated using the new operator, the constructors cannot be called explicitly.<br />You have to do like <br />Test t =  BREAKFAST;<br />Questions no -16 <br />What is the output for the below code ?<br />public class Test {<br />enum Day {<br />MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY<br />}<br />enum Month {<br />JAN, FEB<br />}<br />public static void main(String[] args) {<br />int[] freqArray = { 12, 34, 56, 23, 5, 13, 78 };<br />// Create a Map of frequencies<br />Map<Day, Integer> ordinaryMap = new HashMap<Day, Integer>();<br />for (Day day : Day.values()) {<br />ordinaryMap.put(day, freqArray[day.ordinal()]);<br />}<br />// Create an EnumMap of frequencies<br />EnumMap<Day, Integer> frequencyEnumMap = new EnumMap<Day, Integer>(ordinaryMap);<br />// Change some frequencies<br />frequencyEnumMap.put(null, 100);<br />System.out.println(quot;
Frequency EnumMap: quot;
 + frequencyEnumMap);<br />}<br />}<br />options<br />A)Frequency EnumMap: {MONDAY=12, TUESDAY=34, WEDNESDAY=56, THURSDAY=23, FRIDAY=5, SATURDAY=13, SUNDAY=78}<br />B)Compile Error <br />C)NullPointerException<br />D)Frequency EnumMap: {MONDAY=100, TUESDAY=34, WEDNESDAY=56, THURSDAY=23, FRIDAY=5, SATURDAY=13, SUNDAY=123}<br />Correct answer is : C<br />Explanations : The null reference as a key is NOT permitted.<br />Questions no -17 <br />public class EnumTypeDeclarations {<br />public void foo() {<br />enum SimpleMeal { <br />BREAKFAST, LUNCH, DINNER <br />}<br />}<br />}<br />Is the above code Compile without error ?<br />options<br />A)Compile without error<br />B)Compile with error<br />C)Compile without error but Runtime Exception<br />D)Compile without error but Enum Exception<br />Correct answer is : B<br />Explanations :<br />An enum declaration is a special kind of class declaration:<br />a) It can be declared at the top-level and as static enum declaration. <br />b) It is implicitly static, i.e. no outer object is associated with an enum constant. <br />c) It is implicitly final unless it contains constant-specific class bodies, but it can implement interfaces. <br />d) It cannot be declared abstract unless each abstract method is overridden in the constant-specific class body of every enum constant. <br />e) Local (inner) enum declaration is NOT OK! <br />Here in<br />public void foo() {<br />enum SimpleMeal { <br />BREAKFAST, LUNCH, DINNER <br />}<br />}<br />enum declaration is local within method so compile time error.<br />Questions no -18 <br />What is the output for the below code ?<br />public enum Test {<br />int t;<br />BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45);<br />private int hh;<br />private int mm;<br />Test(int hh, int mm) {<br />assert (hh >= 0 && hh <= 23) : quot;
Illegal hour.quot;
;<br />assert (mm >= 0 && mm <= 59) : quot;
Illegal mins.quot;
;<br />this.hh = hh;<br />this.mm = mm;<br />}<br />public int getHour() {<br />return hh;<br />}<br />public int getMins() {<br />return mm;<br />}<br />public static void main(String args[]){<br />Test t =  BREAKFAST;<br />System.out.println(t.getHour() +quot;
:quot;
+t.getMins());<br />}<br />}<br />options<br />A)7:30<br />B)Compile Error <br />C)12:15<br />D)19:45<br />Correct answer is : B<br />Explanations : The enum constants must be declared before any other declarations in an enum type.<br />In this case compile error because of declaration int t; before enum declaration.<br />Questions no -19 <br />What is the output for the below code ?<br />public class B extends Thread{<br />public static void main(String argv[]){<br />B b = new B();<br />b.run();<br />} <br />public void start(){<br />for (int i = 0; i < 10; i++){<br />System.out.println(quot;
Value of i = quot;
 + i); <br />}  <br />}<br />}<br />options<br />A)A compile time error indicating that no run method is defined for the Thread class<br />B)A run time error indicating that no run method is defined for the Thread class<br />C)Clean compile and at run time the values 0 to 9 are printed out<br />D)Clean compile but no output at runtime<br />Correct answer is : D<br />Explanations : This is a bit of a sneaky one as I have swapped around the names of the methods you need to define and call when running a thread. If the for loop were defined in a method called public void run() and the call in the main method had been to b.start() The list of values from 0 to 9 would have been output.<br />Questions no -20 <br />What is the output for the below code ?<br />public class Test extends Thread{<br />    static String sName = quot;
goodquot;
;<br />    public static void main(String argv[]){<br />    Test t = new Test();<br />    t.nameTest(sName);<br />    System.out.println(sName);<br />    <br />    }<br />    public void nameTest(String sName){<br />            sName = sName + quot;
 idea quot;
;<br />             start();<br />    }<br />    public void run(){<br />    <br />    for(int i=0;i  <  4; i++){<br />            sName = sName + quot;
 quot;
 + i;<br />            <br />    }<br />    }<br />}<br />options<br />A)good<br />B)good idea<br />C)good idea good idea<br />D)good 0 good 0 1<br />Correct answer is : A<br />Explanations : Change value in local methods wouldn’t change in global in case of String ( because String object is immutable).<br />Questions no -21 <br />What is the output for the below code ?<br />public class Test{<br />public static void main(String argv[]){<br />Test1 pm1 = new Test1(quot;
Onequot;
);<br />pm1.run();<br />Test1 pm2 = new Test1(quot;
Twoquot;
);<br />pm2.run();<br />}<br />}<br />class Test1 extends Thread{<br />private String sTname=quot;
quot;
;<br />Test1(String s){<br />sTname = s;<br />}<br />public void run(){<br />for(int i =0; i < 2 ; i++){<br />try{<br /> sleep(1000);<br />}catch(InterruptedException e){}<br />yield();<br />System.out.println(sTname);<br />}<br />}<br />}<br />options<br />A)Compile error<br />B)One One Two Two<br />C)One Two One Two<br />D)One Two<br />Correct answer is : B<br />Explanations : If you call the run method directly it just acts as any other method and does not return to the calling code until it has finished. executing<br />Questions no -22 <br />What is the output for the below code ?<br />public class Test extends Thread{<br />    public static void main(String argv[]){<br />        Test  b = new Test();<br />        b.start();<br />    }<br />    public void run(){      <br />        System.out.println(quot;
Runningquot;
);<br />    }<br />}<br />options<br />A)Compilation clean and run but no output<br />B)Compilation and run with the output quot;
Runningquot;
<br />C)Compile time error with complaint of no Thread import<br />D)Compile time error with complaint of no access to Thread package<br />Correct answer is : B<br />Explanations :<br />The Thread class is part of the core java.lang package and does not need any explicit import statement.<br />Questions no -23 <br />What is the output for the below code ?<br />public class Tech {<br /> public void tech() {<br />      System.out.println(quot;
Techquot;
);<br />   }<br />}<br />public class Atech {<br />Tech a = new Tech() {      <br />      public void tech() {<br />         System.out.println(quot;
anonymous techquot;
);<br />      }<br />   };<br />   <br />   public void dothis() {<br />      a.tech();     <br />      <br />   }<br />public static void main(String... args){<br />Atech atech = new Atech();<br />atech.dothis();<br />}<br />options<br />A)anonymous tech<br />B)Compile Error <br />C)Tech<br />D)anonymous tech Tech<br />Correct answer is : A<br />Explanations : This is anonymous subclass of the specified class type.<br />Anonymous inner class ( anonymous subclass ) overriden the Tech super class of tech() method.<br />Therefore Subclass method will get called.<br />Questions no -24 <br />What is the output for the below code ?<br />public class Outer {<br /> private String x = quot;
Outer variablequot;
;<br />   void doStuff() {<br />     String z = quot;
local variablequot;
;<br />     class Inner {<br />       public void seeOuter() {<br />         System.out.println(quot;
Outer x is quot;
 + x);<br />         System.out.println(quot;
Local variable z is quot;
 + z);  <br />       } <br />     }   <br />   }  <br />   <br />  <br />}<br />options<br />A)Outer x is Outer variable.<br />B)Compile Error <br />C)Local variable z is local variable.<br />D)Outer x is Outer variable Local variable z is local variable<br />Correct answer is : B<br />Explanations : Cannot refer to a non-final variable z inside an inner class defined in a different method.<br />Questions no -25<br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br />for(int i = 2; i < 4; i++)<br />  for(int j = 2; j < 4; j++)<br />     assert i!=j : i; <br />}<br />}<br />options<br />A)The class compiles and runs, but does not print anything.<br />B)The number 2 gets printed with AssertionError<br />C)The number 3 gets printed with AssertionError<br />D)compile error<br />Correct answer is : B<br />Explanations : When i and j are both 2, assert condition is false, and AssertionError gets generated. <br />Questions no -26<br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br />for(int i = 2; i < 4; i++)<br />  for(int j = 2; j < 4; j++)<br />if(i < j)<br />     assert i!=j : i; <br />}<br />}<br />options<br />A)The class compiles and runs, but does not print anything.<br />B)The number 2 gets printed with AssertionError<br />C)The number 3 gets printed with AssertionError<br />D)compile error<br />Correct answer is : A<br />Explanations : When if condition returns true, the assert statement also returns true.<br />Hence AssertionError not generated.<br />Questions no -26 <br />What is the output for the below code ?<br />public class NameBean {<br />private String str;<br />NameBean(String str ){<br />this.str = str;<br />}<br />public String toString() {<br />return str;<br />}<br />}<br />import java.util.HashSet;<br />public class CollClient {<br />public static void main(String ... sss) {<br />HashSet myMap = new HashSet();<br />String s1 = new String(quot;
dasquot;
);<br />String s2 = new String(quot;
dasquot;
);<br />NameBean s3 = new NameBean(quot;
abcdefquot;
);<br />NameBean s4 = new NameBean(quot;
abcdefquot;
);<br />myMap.add(s1);<br />myMap.add(s2);<br />myMap.add(s3);<br />myMap.add(s4);<br />System.out.println(myMap);<br />}<br />}<br />options<br />A)das abcdef abcdef<br />B)das das abcdef abcdef<br />C)das abcdef<br />D)abcdef abcdef<br />Correct answer is : A<br />Explanations : Need to implement 'equals' and 'hashCode' methods to get unique Set for user defind objects(NameBean).<br />String object internally implements 'equals' and 'hashCode' methods therefore Set only stored one value.<br />Questions no -27 <br />Synchronized resizable-array implementation of the List interface is _____________?<br />options<br />A)Vector<br />B)ArrayList<br />C)Hashtable<br />D)HashMap<br />Correct answer is : A<br />Explanations : Vector implements List, RandomAccess - Synchronized resizable-array implementation of the List interface with additional quot;
legacy methods.quot;
<br />Questions no -28 <br />What is the output for the below code ?<br />public class Test {<br />    <br />    public static void main(String argv[]){<br />     <br />    ArrayList list = new ArrayList(); <br />    ArrayList<String> listStr = list; <br />    ArrayList<StringBuffer> listBuf = list; <br />    listStr.add(0, quot;
Helloquot;
); <br />    StringBuffer buff = listBuf.get(0); <br />       System.out.println(buff.toString());<br />    }<br />}<br />options<br />A)Hello<br />B)Compile error<br />C)java.lang.ClassCastException<br />D)null<br />Correct answer is : C<br />Explanations : java.lang.String cannot be cast to java.lang.StringBuffer at the code StringBuffer buff = listBuf.get(0); <br />So thows java.lang.ClassCastException.<br />Questions no -29 <br />What is the output for the below code ?<br />import java.util.LinkedList;<br />import java.util.Queue;<br />public class Test {<br />public static void main(String... args) {<br />        <br />Queue<String> q = new LinkedList<String>();<br />        q.add(quot;
newyorkquot;
);<br />        q.add(quot;
caquot;
);<br />        q.add(quot;
texasquot;
);<br />        show(q);<br />    }<br />    public static void show(Queue q) {<br />        q.add(new Integer(11));<br />        while (!q.isEmpty ( ) )<br />            System.out.print(q.poll() + quot;
  quot;
);<br />    }<br />}<br />options<br />A)Compile error : Integer can't add<br />B)newyork  ca  texas  11<br />C)newyork  ca  texas<br />D)newyork  ca <br />Correct answer is : B<br />Explanations : <br />  q was originally declared as Queue<String>,  But in show() method it is passed as an untyped Queue. nothing in the compiler or JVM prevents us from adding an Integer after that.<br />   If the show method signature is public static void show(Queue<String> q) than you can't add Integer, Only String allowed. But public static void show(Queue q) is untyped Queue so you can add Integer.<br />  poll() Retrieves and removes the head of this queue, or returns null if this queue is empty.<br />Questions no -30 <br />What is the output for the below code ?<br />public interface TestInf {<br /> int i =10;<br />}<br />public class Test {<br />public static void main(String... args) {<br />TestInf.i=12;<br />System.out.println(TestInf.i);<br />}<br />}<br />options<br />A)Compile with error<br />B)10<br />C)12<br />D) Runtime Exception<br />Correct answer is : A<br />Explanations : All the variables declared in interface is Implicitly static and final , therefore can't change the value.<br />Questions no -31 <br />What is the output for the below code ?<br />public class Test {<br />            static { int a = 5; }<br />            public static void main(String[] args){<br />            System.out.println(a);<br />            }<br />          }<br />options<br />A)Compile with error<br />B)5<br />C)0<br />D) Runtime Exception<br />Correct answer is : A<br />Explanations : A variable declared  in a static initialiser is not accessible outside its enclosing block.<br />Questions no -32 <br />What is the output for the below code ?<br />class A {<br />  { System.out.print(quot;
b1 quot;
); }<br />  public A() { System.out.print(quot;
b2 quot;
); }<br />}<br />class B extends A {<br />  static { System.out.print(quot;
r1 quot;
); }<br />  public B() { System.out.print(quot;
r2 quot;
); }<br />  { System.out.print(quot;
r3 quot;
); }<br />  static { System.out.print(quot;
r4 quot;
); }<br />}<br />class C extends B {<br />  public static void main(String[] args) {<br />    System.out.print(quot;
pre quot;
);<br />    new C();<br />    System.out.println(quot;
post quot;
);<br />  }<br />}<br />options<br />A)r1 r4 pre b1 b2 r3 r2 post<br />B)r1 r4 pre b1 b2  post<br />C)r1 r4 pre b1 b2  post r3 r2<br />D)pre r1 r4  b1 b2  r2 r3 post<br />Correct answer is : A<br />Explanations : All static blocks execute first then blocks and constructor. <br />Blocks and constructor executes (super class block then super class constructor, sub class block then sub class constructor).<br />Sequence for static blocks is super class first then sub class.<br />Sequence for blocks is super class first then sub class.<br />Questions no -33 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) throws Exception {<br />Integer i = 34;<br />int l = 34;<br />if(i.equals(l)){<br />System.out.println(true);<br />}else{<br />System.out.println(false);<br />}<br />}<br />}<br />options<br />A)true<br />B)false<br />C)Compile Error<br />D) Runtime Exception<br />Correct answer is : A<br />Explanations : equals() method for the integer wrappers will only return true if the two primitive types and the two values are equal.<br />Questions no -34 <br />Which statement is true about outer class?<br />options<br />A)outer class can only declare public , abstract and final<br />B)outer class may be private<br />C)outer class can't be abstract<br />D)outer class can be static<br />Correct answer is : A<br />Explanations : outer class can only declare public , abstract and final.<br />Questions no -35 <br />What is the output for the below code ?<br />static public class Test {<br />public static void main(String[] args) {<br />  char c = 'a';<br /> switch(c){<br />     case 65:<br />              System.out.println(quot;
onequot;
);break;<br />     case 'a':<br />              System.out.println(quot;
twoquot;
);break;<br />     case 3:<br />              System.out.println(quot;
threequot;
);<br />}<br />}<br />}<br />options<br />A)one<br />B)two<br />C)Compile error - char can't be permitted in switch statement <br />D)Compile error - Illegal modifier for the class Test; only public, abstract & final are permitted.<br />Correct answer is : D<br />Explanations : outer class can only declare public , abstract and final.<br />Illegal modifier for the class Test; only public, abstract & final are permitted<br />Questions no -36<br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br />ArrayList<Integer> list = new ArrayList<Integer>();<br />list.add(1);<br />list.add(2);<br />list.add(3);<br />for(int i:list)<br />System.out.println(i);<br />}<br />}<br />options<br />A)1 2 3<br />B)Compile error , can't add primitive type in ArrayList<br />C)Compile error on for(int i:list) , Incorrect Syntax<br />D)0 0 0<br />Correct answer is : A<br />Explanations : JDK 1.5, 1.6 allows add primitive type in ArrayList  and for(int i:list) syntax is also correct.<br />for(int i:list) is same as <br />for(int i=0; i < list.size();i++){<br />int a = list.get(i);<br />}<br />Questions no -37 <br />What is the output for the below code ?<br />public class SuperClass {<br />public int doIt(String str, Integer... data)throws ArrayIndexOutOfBoundsException{<br />String signature = quot;
(String, Integer[])quot;
;<br />System.out.println(str + quot;
  quot;
 + signature);<br />return 1;<br />}<br />}<br />public class SubClass extends SuperClass{<br />public int doIt(String str, Integer... data) throws Exception<br />{<br />String signature = quot;
(String, Integer[])quot;
;<br />System.out.println(quot;
Overridden: quot;
 + str + quot;
 quot;
 + signature);<br />return 0;<br />}<br />public static void main(String... args)<br />{<br />SuperClass sb = new SubClass();<br />try{<br />sb.doIt(quot;
helloquot;
, 3);<br />}catch(Exception e){<br />}<br />}<br />}<br />options<br />A)Overridden: hello (String, Integer[])<br />B)hello (String, Integer[])<br />C)This code throws an Exception at Runtime<br />D)Compile with error<br />Correct answer is : D<br />Explanations : Exception Exception is not compatible with throws clause in SuperClass.doIt(String, Integer[]). <br />The same exception or subclass of that exception is allowed.<br />Questions no -38<br />What is the result of executing the following code, using the parameters 0 and 3 ?<br />public void divide(int a, int b) {<br />try {<br />int c = a / b;<br />} catch (Exception e) {<br />System.out.print(quot;
Exception quot;
);<br />} finally {<br />System.out.println(quot;
Finallyquot;
);<br />}<br />options<br />A)Prints out: Exception Finally<br />B)Prints out: Finally<br />C)Prints out: Exception<br />D)Compile with error<br />Correct answer is : B<br />Explanations : finally block always executed whether exception occurs or not. <br />0/3 = 0 Does not throws exception.<br />Questions no -39<br />Which of the below statement is true about Error?<br />options<br />A)An Error is a subclass of Throwable<br />B)An Error is a subclass of Exception<br />C)Error indicates serious problems that a reasonable application should not try to catch.<br />D)An Error is a subclass of IOException<br />Correct answer is : A and C<br />Explanations : An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.<br />Questions no -40<br />Which of the following is type of RuntimeException?<br />options<br />A)IOException<br />B)ArrayIndexOutOfBoundsException<br />C)Exception<br />D)Error<br />Correct answer is : B<br />Explanations : Below is the tree.<br />java.lang.Object<br />  java.lang.Throwable<br />      java.lang.Exception<br />          java.lang.RuntimeException<br />              java.lang.IndexOutOfBoundsException<br />                  java.lang.ArrayIndexOutOfBoundsException<br />Questions no -41 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) throws Exception {<br /> File file = new File(quot;
test.txtquot;
);  <br /> System.out.println(file.exists());<br /> FileWriter fw = new FileWriter(file); <br /> System.out.println(file.exists());<br />}<br />}<br />options<br />A)true true<br />B)false false<br />C)false true<br />D)true false<br />Correct answer is : C<br />Explanations :Creating a new instance of the class File, you're not yet making an actual file, you're just creating a filename.<br />So file.exists() return false.<br />FileWriter fw = new FileWriter(file) do three things:<br />It created a FileWriter reference variable fw.<br />It created a FileWriter object, and assigned it to fw.<br />It created an actual empty file out on the disk.<br />So file.exists() return true.<br />Questions no -42 <br />When comparing java.io.BufferedWriter and java.io.FileWriter, which capability exist as a method in only one of two ?<br />options<br />A)closing the stream<br />B)flushing the stream<br />C)writting to the stream<br />D)writting a line separator to the stream<br />Correct answer is : D<br />Explanations :A newLine() method is provided in BufferedWriter which is not in FileWriter.<br />Questions no -43 <br />What is the output for the below code ?<br />public class Test{<br />public static void main(String[] args) {<br />  int i1=1;<br /> switch(i1){<br />     case 1:<br />              System.out.println(quot;
onequot;
);<br />     case 2:<br />              System.out.println(quot;
twoquot;
);<br />     case 3:<br />              System.out.println(quot;
threequot;
);<br />}<br />}<br />}<br />options<br />A)one two three<br />B)one<br />C)one two<br />D)Compile error.<br />Correct answer is : A<br />Explanations : There is no break statement in case 1 so it causes the below case statements to execute regardless of their values.<br />Questions no -44 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String[] args) {<br />  char c = 'a';<br /> switch(c){<br />     case 65:<br />              System.out.println(quot;
onequot;
);break;<br />     case 'a':<br />              System.out.println(quot;
twoquot;
);break;<br />     case 3:<br />              System.out.println(quot;
threequot;
);<br />}<br />}<br />}<br />options<br />A)one two three<br />B)one<br />C)two<br />D)Compile error - char can't be in switch statement.<br />Correct answer is : C<br />Explanations : Compile properly and print two.<br />Questions no -45 <br />What is the output for the below code ?<br />import java.util.NavigableMap;<br />import java.util.concurrent.ConcurrentSkipListMap;<br />public class Test {<br />public static void main(String... args) {<br />        <br />NavigableMap <Integer, String>navMap = new <br />        ConcurrentSkipListMap<Integer, String>();<br />navMap.put(4, quot;
Aprilquot;
);<br />navMap.put(5, quot;
Mayquot;
);<br />navMap.put(6, quot;
Junequot;
);<br />navMap.put(1, quot;
Januaryquot;
);<br />navMap.put(2, quot;
Februaryquot;
);<br />navMap.put(3, quot;
Marchquot;
);<br />        navMap.pollFirstEntry();<br />        navMap.pollLastEntry();<br />        navMap.pollFirstEntry();<br />        System.out.println(navMap.size());<br />           <br />}<br />}<br />options<br />A)Compile error : No method  name like pollFirstEntry() or pollLastEntry()<br />B)3<br />C)6<br />D)4<br />Correct answer is : B<br />Explanations : <br />  pollFirstEntry() Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty.<br />  pollLastEntry() Removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.<br />Questions no -46<br />What is the output for the below code ?<br />import java.util.NavigableMap;<br />import java.util.concurrent.ConcurrentSkipListMap;<br />public class Test {<br />public static void main(String... args) {<br />        <br />NavigableMap <Integer, String>navMap = new <br />        ConcurrentSkipListMap<Integer, String>();<br />        System.out.print(navMap.lastEntry());<br />           <br />}<br />}<br />options<br />A)Compile error : No method  name like lastEntry()<br />B)null<br />C)NullPointerException<br />D)0<br />Correct answer is : B<br />Explanations : lastEntry() Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.<br />Questions no -47<br />What is the output for the below code ?<br />import java.util.NavigableMap;<br />import java.util.concurrent.ConcurrentSkipListMap;<br />public class Test {<br />public static void main(String... args) {<br />        <br />NavigableMap<Integer, String>navMap = new <br />        ConcurrentSkipListMap<Integer, String>();<br />navMap.put(4, quot;
Aprilquot;
);<br />navMap.put(5, quot;
Mayquot;
);<br />navMap.put(6, quot;
Junequot;
);<br />navMap.put(1, quot;
Januaryquot;
);<br />navMap.put(2, quot;
Februaryquot;
);<br />        System.out.print(navMap.ceilingKey(3));<br />        <br />           <br />}<br />}<br />options<br />A)Compile error : No method  name like ceilingKey()<br />B)null<br />C)NullPointerException<br />D)4<br />Correct answer is : D<br />Explanations : Returns the least key greater than or equal to the given key, or null if there is no such key. <br />In the above case : 3 is not a key so return 4 (least key greater than or equal to the given key).<br />Questions no -48<br />What is the output for the below code ?<br />import java.util.NavigableMap;<br />import java.util.concurrent.ConcurrentSkipListMap;<br />public class Test {<br />public static void main(String... args) {<br />        <br />NavigableMap<Integer, String>navMap = new <br />        ConcurrentSkipListMap<Integer, String>();<br />navMap.put(4, quot;
Aprilquot;
);<br />navMap.put(5, quot;
Mayquot;
);<br />navMap.put(6, quot;
Junequot;
);<br />navMap.put(1, quot;
Januaryquot;
);<br />navMap.put(2, quot;
Februaryquot;
);<br />        System.out.print(navMap.floorKey(3));<br />        <br />           <br />}<br />}<br />options<br />A)Compile error : No method  name like floorKey()<br />B)null<br />C)NullPointerException<br />D)2<br />Correct answer is : D<br />Explanations : Returns the greatest key less than or equal to the given key, or null if there is no such key. <br />In the above case : 3 is not a key so return 2 (greatest key less than or equal to the given key).<br />Questions no -49 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br />        <br /> List<Integer> lst = new ArrayList<Integer>();<br /> lst.add(34);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(5);<br />         <br />        NavigableSet<Integer>  nvset = new TreeSet(lst);<br />        System.out.println(nvset.tailSet(6));<br />           <br />}<br />}<br />options<br />A)Compile error : No method  name like tailSet()<br />B)6 34<br />C)5<br />D)5 6 34<br />Correct answer is : B<br />Explanations : tailSet(6) Returns elements are greater than or equal to 6.<br />Questions no -50 <br />What is the output for the below code ?<br />import java.util.ArrayList;<br />import java.util.List;<br />import java.util.NavigableSet;<br />import java.util.TreeSet;<br />public class Test {<br />public static void main(String... args) {<br />        <br />List<Integer> lst = new ArrayList<Integer>();<br /> lst.add(34);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(6);<br />         <br />        NavigableSet<Integer>  nvset = new TreeSet(lst);<br />        nvset.pollFirst(); <br />        nvset.pollLast();<br />            System.out.println(nvset.size());<br />           <br />}<br />}<br />options<br />A)Compile error : No method  name like pollFirst() or pollLast()<br />B)0<br />C)3<br />D)5<br />Correct answer is : B<br />Explanations : <br />  pollFirst() Retrieves and removes the first (lowest) element, or returns null if this set is empty.<br />  pollLast() Retrieves and removes the last (highest) element, or returns null if this set is empty.<br />Questions no -51<br />What is the output for the below code ?<br />import java.util.ArrayList;<br />import java.util.List;<br />import java.util.NavigableSet;<br />import java.util.TreeSet;<br />public class Test {<br />public static void main(String... args) {<br />        <br /> List<Integer> lst = new ArrayList<Integer>();<br /> lst.add(34);<br /> lst.add(6);<br /> lst.add(2);<br /> lst.add(8);<br />     lst.add(7);<br />     lst.add(10);<br />        <br />        NavigableSet<Integer>  nvset = new TreeSet(lst);<br />        System.out.println(nvset.lower(6)+quot;
 quot;
+nvset.higher(6)+ quot;
 quot;
+ nvset.lower(2));<br />      <br />}<br />}<br />options<br />A)1 2 7 10 34 null<br />B)2 7 null<br />C)2 7 34<br />D)1 2 7 10 34<br />Correct answer is : B<br />Explanations : <br />  lower() Returns the greatest element in this set strictly less than the given element, or null if there is no such element.<br />  higher() Returns the least element in this set strictly greater than the given element, or null if there is no such element.<br />Questions no -52<br />What is the output for the below code ?<br />import java.util.ArrayList;<br />import java.util.Iterator;<br />import java.util.List;<br />import java.util.NavigableSet;<br />import java.util.TreeSet;<br />public class Test {<br />public static void main(String... args) {<br />        <br /> List<Integer> lst = new ArrayList<Integer>();<br /> lst.add(34);<br /> lst.add(6);<br /> lst.add(2);<br /> lst.add(8);<br />     lst.add(7);<br />     lst.add(10);<br />        <br />        NavigableSet<Integer>  nvset = new TreeSet(lst);<br />         System.out.println(nvset.headSet(10));<br />      <br />}<br />}<br />options<br />A)Compile error : No method  name like headSet()<br />B)2, 6, 7, 8, 10<br />C)2, 6, 7, 8<br />D)34<br />Correct answer is : C<br />Explanations : <br />  headSet(10) Returns the elements elements are strictly less than 10.<br />  headSet(10,false) Returns the elements elements are strictly less than 10.<br />  headSet(10,true) Returns the elements elements are strictly less than or equal to 10.<br />Questions no -53 <br />What is the output for the below code ?<br />import java.io.Console;<br />public class Test {<br />public static void main(String... args) {<br />        <br />Console con = System.console();<br />  boolean auth = false;<br /> <br />  if (con != null)<br />  {<br />    int count = 0;<br />    do<br />    {<br />      String uname = con.readLine(null);<br />      char[] pwd = con.readPassword(quot;
Enter %s's password: quot;
, uname);<br />      <br />      con.writer().write(quot;
quot;
);  <br />    } while (!auth && ++count < 3);<br />  }<br />           <br />}<br />}<br />options<br />A)NullPointerException<br />B)It works properly<br />C)Compile Error : No readPassword() method in Console class.<br />D)null<br />Correct answer is : A<br />Explanations : passing a null argument to any method in Console class will cause a NullPointerException to be thrown.<br />
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7

More Related Content

What's hot

SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8
Chaitanya Ganoo
 
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
Ganesh Samarthyam
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
Dror Helper
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
Nishan Barot
 
Java level 1 Quizzes
Java level 1 QuizzesJava level 1 Quizzes
Java level 1 QuizzesSteven Luo
 
Java Quiz
Java QuizJava Quiz
Java Quiz
Dharmraj Sharma
 
Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
mehul patel
 
TDD CrashCourse Part4: Improving Testing
TDD CrashCourse Part4: Improving TestingTDD CrashCourse Part4: Improving Testing
TDD CrashCourse Part4: Improving Testing
David Rodenas
 
E5
E5E5
E5
lksoo
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
Knowledge Center Computer
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and Answers
Rumman Ansari
 
Part - 2 Cpp programming Solved MCQ
Part - 2  Cpp programming Solved MCQ Part - 2  Cpp programming Solved MCQ
Part - 2 Cpp programming Solved MCQ
Knowledge Center Computer
 
report
reportreport
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewPaulo Morgado
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
Ganesh Samarthyam
 
Symbolic Execution And KLEE
Symbolic Execution And KLEESymbolic Execution And KLEE
Symbolic Execution And KLEE
Shauvik Roy Choudhary, Ph.D.
 

What's hot (20)

SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8
 
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
 
Java level 1 Quizzes
Java level 1 QuizzesJava level 1 Quizzes
Java level 1 Quizzes
 
Java Quiz
Java QuizJava Quiz
Java Quiz
 
Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
 
Scjp6.0
Scjp6.0Scjp6.0
Scjp6.0
 
TDD CrashCourse Part4: Improving Testing
TDD CrashCourse Part4: Improving TestingTDD CrashCourse Part4: Improving Testing
TDD CrashCourse Part4: Improving Testing
 
E5
E5E5
E5
 
Core java
Core javaCore java
Core java
 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and Answers
 
Part - 2 Cpp programming Solved MCQ
Part - 2  Cpp programming Solved MCQ Part - 2  Cpp programming Solved MCQ
Part - 2 Cpp programming Solved MCQ
 
report
reportreport
report
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Symbolic Execution And KLEE
Symbolic Execution And KLEESymbolic Execution And KLEE
Symbolic Execution And KLEE
 
Java programs
Java programsJava programs
Java programs
 

Viewers also liked

Evaluation of practical product
Evaluation of practical productEvaluation of practical product
Evaluation of practical productJustine Hill
 
Evaluation of practical_product
Evaluation of practical_productEvaluation of practical_product
Evaluation of practical_productJustine Hill
 
Presentation for aug 11
Presentation for aug 11Presentation for aug 11
Presentation for aug 11SyedAhmedAli31
 
Dasar TOC show
Dasar TOC showDasar TOC show
Dasar TOC show
ekosudarmanto
 
The 2020 business by sam fiorella sensei
The 2020 business by sam fiorella   senseiThe 2020 business by sam fiorella   sensei
The 2020 business by sam fiorella sensei
Sam Fiorella
 
6 2 2_jesus_arias_valencia
6 2 2_jesus_arias_valencia6 2 2_jesus_arias_valencia
6 2 2_jesus_arias_valenciachristian2208r
 
الذاكرة الالكترونية
الذاكرة الالكترونيةالذاكرة الالكترونية
الذاكرة الالكترونية
NADA SAMER
 
Talk at BaseSpace Developer conference SF 2013
Talk at BaseSpace Developer conference SF 2013Talk at BaseSpace Developer conference SF 2013
Talk at BaseSpace Developer conference SF 2013Zayed Albertyn
 
Sam fiorella senseimarketing_socialmediamasters_toronto_oct72011
Sam fiorella senseimarketing_socialmediamasters_toronto_oct72011Sam fiorella senseimarketing_socialmediamasters_toronto_oct72011
Sam fiorella senseimarketing_socialmediamasters_toronto_oct72011
Sam Fiorella
 
Social Media ROI at AIMSCda by @samfiorella
Social Media ROI at AIMSCda  by @samfiorellaSocial Media ROI at AIMSCda  by @samfiorella
Social Media ROI at AIMSCda by @samfiorella
Sam Fiorella
 
E learning university social - content marketing - sam fiorella
E learning university social - content marketing - sam fiorellaE learning university social - content marketing - sam fiorella
E learning university social - content marketing - sam fiorella
Sam Fiorella
 
Social sales influencemktg_samfiorella_april2014
Social sales influencemktg_samfiorella_april2014Social sales influencemktg_samfiorella_april2014
Social sales influencemktg_samfiorella_april2014
Sam Fiorella
 
Kajian tindakan.pptx skconventmuar(kak min min)
Kajian tindakan.pptx  skconventmuar(kak min min)Kajian tindakan.pptx  skconventmuar(kak min min)
Kajian tindakan.pptx skconventmuar(kak min min)
Kak Min Min
 
Why Do They (Terrorists) Hate Us?
Why Do They (Terrorists) Hate Us?Why Do They (Terrorists) Hate Us?
Why Do They (Terrorists) Hate Us?
Erik Malin
 
العرض الذى قدمته "وحدة الذاكرة الالكترونية " فى الاحتفال الذي اقامته كلية الآ...
العرض الذى قدمته "وحدة الذاكرة الالكترونية " فى الاحتفال الذي اقامته كلية الآ...العرض الذى قدمته "وحدة الذاكرة الالكترونية " فى الاحتفال الذي اقامته كلية الآ...
العرض الذى قدمته "وحدة الذاكرة الالكترونية " فى الاحتفال الذي اقامته كلية الآ...
NADA SAMER
 
Selesaikan masalah tolak berikut ( KSSR THN 2 & 3 )
Selesaikan masalah tolak berikut ( KSSR THN 2 & 3 )Selesaikan masalah tolak berikut ( KSSR THN 2 & 3 )
Selesaikan masalah tolak berikut ( KSSR THN 2 & 3 )
Kak Min Min
 

Viewers also liked (19)

More research
More research More research
More research
 
Research
ResearchResearch
Research
 
Evaluation of practical product
Evaluation of practical productEvaluation of practical product
Evaluation of practical product
 
Evaluation of practical_product
Evaluation of practical_productEvaluation of practical_product
Evaluation of practical_product
 
Presentation for aug 11
Presentation for aug 11Presentation for aug 11
Presentation for aug 11
 
Dasar TOC show
Dasar TOC showDasar TOC show
Dasar TOC show
 
The 2020 business by sam fiorella sensei
The 2020 business by sam fiorella   senseiThe 2020 business by sam fiorella   sensei
The 2020 business by sam fiorella sensei
 
6 2 2_jesus_arias_valencia
6 2 2_jesus_arias_valencia6 2 2_jesus_arias_valencia
6 2 2_jesus_arias_valencia
 
الذاكرة الالكترونية
الذاكرة الالكترونيةالذاكرة الالكترونية
الذاكرة الالكترونية
 
Talk at BaseSpace Developer conference SF 2013
Talk at BaseSpace Developer conference SF 2013Talk at BaseSpace Developer conference SF 2013
Talk at BaseSpace Developer conference SF 2013
 
Sam fiorella senseimarketing_socialmediamasters_toronto_oct72011
Sam fiorella senseimarketing_socialmediamasters_toronto_oct72011Sam fiorella senseimarketing_socialmediamasters_toronto_oct72011
Sam fiorella senseimarketing_socialmediamasters_toronto_oct72011
 
Social Media ROI at AIMSCda by @samfiorella
Social Media ROI at AIMSCda  by @samfiorellaSocial Media ROI at AIMSCda  by @samfiorella
Social Media ROI at AIMSCda by @samfiorella
 
E learning university social - content marketing - sam fiorella
E learning university social - content marketing - sam fiorellaE learning university social - content marketing - sam fiorella
E learning university social - content marketing - sam fiorella
 
Social sales influencemktg_samfiorella_april2014
Social sales influencemktg_samfiorella_april2014Social sales influencemktg_samfiorella_april2014
Social sales influencemktg_samfiorella_april2014
 
Kajian tindakan.pptx skconventmuar(kak min min)
Kajian tindakan.pptx  skconventmuar(kak min min)Kajian tindakan.pptx  skconventmuar(kak min min)
Kajian tindakan.pptx skconventmuar(kak min min)
 
Why Do They (Terrorists) Hate Us?
Why Do They (Terrorists) Hate Us?Why Do They (Terrorists) Hate Us?
Why Do They (Terrorists) Hate Us?
 
العرض الذى قدمته "وحدة الذاكرة الالكترونية " فى الاحتفال الذي اقامته كلية الآ...
العرض الذى قدمته "وحدة الذاكرة الالكترونية " فى الاحتفال الذي اقامته كلية الآ...العرض الذى قدمته "وحدة الذاكرة الالكترونية " فى الاحتفال الذي اقامته كلية الآ...
العرض الذى قدمته "وحدة الذاكرة الالكترونية " فى الاحتفال الذي اقامته كلية الآ...
 
Permohonan PBB baru
Permohonan PBB baruPermohonan PBB baru
Permohonan PBB baru
 
Selesaikan masalah tolak berikut ( KSSR THN 2 & 3 )
Selesaikan masalah tolak berikut ( KSSR THN 2 & 3 )Selesaikan masalah tolak berikut ( KSSR THN 2 & 3 )
Selesaikan masalah tolak berikut ( KSSR THN 2 & 3 )
 

Similar to 7

Core java
Core javaCore java
Core java
prabhatjon
 
sample_midterm.pdf
sample_midterm.pdfsample_midterm.pdf
sample_midterm.pdf
EFRENlazarte2
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
krtioplal
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
raksharao
 
FSOFT - Test Java Exam
FSOFT - Test Java ExamFSOFT - Test Java Exam
FSOFT - Test Java Exam
Nguyễn Đăng Đức
 
Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answers
Sushant Choudhary
 
Technical aptitude test 2 CSE
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSE
Sujata Regoti
 
OOP with Java - continued
OOP with Java - continuedOOP with Java - continued
OOP with Java - continued
RatnaJava
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
Maýur Chourasiya
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional
Isabella789
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
mayorothenguyenhob69
 
Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011Devnology
 
C test
C testC test
1z0 808[1]
1z0 808[1]1z0 808[1]
1z0 808[1]
hildebrando vargas
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
praveensomesh
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
CodeOps Technologies LLP
 
Conceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a ObjetosConceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a Objetos
guest22a621
 
Questões de Certificação SCJP
Questões de Certificação SCJPQuestões de Certificação SCJP
Questões de Certificação SCJP
José Maria Silveira Neto
 

Similar to 7 (19)

Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
Core java
Core javaCore java
Core java
 
sample_midterm.pdf
sample_midterm.pdfsample_midterm.pdf
sample_midterm.pdf
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
 
FSOFT - Test Java Exam
FSOFT - Test Java ExamFSOFT - Test Java Exam
FSOFT - Test Java Exam
 
Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answers
 
Technical aptitude test 2 CSE
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSE
 
OOP with Java - continued
OOP with Java - continuedOOP with Java - continued
OOP with Java - continued
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011
 
C test
C testC test
C test
 
1z0 808[1]
1z0 808[1]1z0 808[1]
1z0 808[1]
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
 
Conceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a ObjetosConceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a Objetos
 
Questões de Certificação SCJP
Questões de Certificação SCJPQuestões de Certificação SCJP
Questões de Certificação SCJP
 

Recently uploaded

DIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptxDIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptx
FarzanaRbcomcs
 
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
foismail170
 
New Explore Careers and College Majors 2024.pdf
New Explore Careers and College Majors 2024.pdfNew Explore Careers and College Majors 2024.pdf
New Explore Careers and College Majors 2024.pdf
Dr. Mary Askew
 
han han widi kembar tapi beda han han dan widi kembar tapi sama
han han widi kembar tapi beda han han dan widi kembar tapi samahan han widi kembar tapi beda han han dan widi kembar tapi sama
han han widi kembar tapi beda han han dan widi kembar tapi sama
IrlanMalik
 
Operating system. short answes and Interview questions .pdf
Operating system. short answes and Interview questions .pdfOperating system. short answes and Interview questions .pdf
Operating system. short answes and Interview questions .pdf
harikrishnahari6276
 
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdfDOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
Pushpendra Kumar
 
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
larisashrestha558
 
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Dirk Spencer Corporate Recruiter LION
 
135. Reviewer Certificate in Journal of Engineering
135. Reviewer Certificate in Journal of Engineering135. Reviewer Certificate in Journal of Engineering
135. Reviewer Certificate in Journal of Engineering
Manu Mitra
 
Full Sail_Morales_Michael_SMM_2024-05.pptx
Full Sail_Morales_Michael_SMM_2024-05.pptxFull Sail_Morales_Michael_SMM_2024-05.pptx
Full Sail_Morales_Michael_SMM_2024-05.pptx
mmorales2173
 
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR GeneralistHeidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
HeidiLivengood
 
How Mentoring Elevates Your PM Career | PMI Silver Spring Chapter
How Mentoring Elevates Your PM Career | PMI Silver Spring ChapterHow Mentoring Elevates Your PM Career | PMI Silver Spring Chapter
How Mentoring Elevates Your PM Career | PMI Silver Spring Chapter
Hector Del Castillo, CPM, CPMM
 
132. Acta Scientific Pharmaceutical Sciences
132. Acta Scientific Pharmaceutical Sciences132. Acta Scientific Pharmaceutical Sciences
132. Acta Scientific Pharmaceutical Sciences
Manu Mitra
 
Brand Identity For A Sportscaster Project and Portfolio I
Brand Identity For A Sportscaster Project and Portfolio IBrand Identity For A Sportscaster Project and Portfolio I
Brand Identity For A Sportscaster Project and Portfolio I
thomasaolson2000
 
Andrea Kate Portfolio Presentation.pdf
Andrea Kate  Portfolio  Presentation.pdfAndrea Kate  Portfolio  Presentation.pdf
Andrea Kate Portfolio Presentation.pdf
andreakaterasco
 
How to Master LinkedIn for Career and Business
How to Master LinkedIn for Career and BusinessHow to Master LinkedIn for Career and Business
How to Master LinkedIn for Career and Business
ideatoipo
 
Personal Brand Exploration Comedy Jxnelle.
Personal Brand Exploration Comedy Jxnelle.Personal Brand Exploration Comedy Jxnelle.
Personal Brand Exploration Comedy Jxnelle.
alexthomas971
 
Widal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid feverWidal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid fever
taexnic
 
The Impact of Artificial Intelligence on Modern Society.pdf
The Impact of Artificial Intelligence on Modern Society.pdfThe Impact of Artificial Intelligence on Modern Society.pdf
The Impact of Artificial Intelligence on Modern Society.pdf
ssuser3e63fc
 
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
foismail170
 

Recently uploaded (20)

DIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptxDIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptx
 
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
 
New Explore Careers and College Majors 2024.pdf
New Explore Careers and College Majors 2024.pdfNew Explore Careers and College Majors 2024.pdf
New Explore Careers and College Majors 2024.pdf
 
han han widi kembar tapi beda han han dan widi kembar tapi sama
han han widi kembar tapi beda han han dan widi kembar tapi samahan han widi kembar tapi beda han han dan widi kembar tapi sama
han han widi kembar tapi beda han han dan widi kembar tapi sama
 
Operating system. short answes and Interview questions .pdf
Operating system. short answes and Interview questions .pdfOperating system. short answes and Interview questions .pdf
Operating system. short answes and Interview questions .pdf
 
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdfDOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
 
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
 
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
 
135. Reviewer Certificate in Journal of Engineering
135. Reviewer Certificate in Journal of Engineering135. Reviewer Certificate in Journal of Engineering
135. Reviewer Certificate in Journal of Engineering
 
Full Sail_Morales_Michael_SMM_2024-05.pptx
Full Sail_Morales_Michael_SMM_2024-05.pptxFull Sail_Morales_Michael_SMM_2024-05.pptx
Full Sail_Morales_Michael_SMM_2024-05.pptx
 
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR GeneralistHeidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
 
How Mentoring Elevates Your PM Career | PMI Silver Spring Chapter
How Mentoring Elevates Your PM Career | PMI Silver Spring ChapterHow Mentoring Elevates Your PM Career | PMI Silver Spring Chapter
How Mentoring Elevates Your PM Career | PMI Silver Spring Chapter
 
132. Acta Scientific Pharmaceutical Sciences
132. Acta Scientific Pharmaceutical Sciences132. Acta Scientific Pharmaceutical Sciences
132. Acta Scientific Pharmaceutical Sciences
 
Brand Identity For A Sportscaster Project and Portfolio I
Brand Identity For A Sportscaster Project and Portfolio IBrand Identity For A Sportscaster Project and Portfolio I
Brand Identity For A Sportscaster Project and Portfolio I
 
Andrea Kate Portfolio Presentation.pdf
Andrea Kate  Portfolio  Presentation.pdfAndrea Kate  Portfolio  Presentation.pdf
Andrea Kate Portfolio Presentation.pdf
 
How to Master LinkedIn for Career and Business
How to Master LinkedIn for Career and BusinessHow to Master LinkedIn for Career and Business
How to Master LinkedIn for Career and Business
 
Personal Brand Exploration Comedy Jxnelle.
Personal Brand Exploration Comedy Jxnelle.Personal Brand Exploration Comedy Jxnelle.
Personal Brand Exploration Comedy Jxnelle.
 
Widal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid feverWidal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid fever
 
The Impact of Artificial Intelligence on Modern Society.pdf
The Impact of Artificial Intelligence on Modern Society.pdfThe Impact of Artificial Intelligence on Modern Society.pdf
The Impact of Artificial Intelligence on Modern Society.pdf
 
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
 

7

  • 1. Questions no -1 <br />What is the output for the below code ?<br />class A implements Runnable{<br />public void run(){<br />System.out.println(Thread.currentThread().getName());<br />} <br />}<br />public class Test {<br />public static void main(String... args) {<br />A a = new A();<br />Thread t = new Thread(a);<br />Thread t1 = new Thread(a);<br />t.setName(quot; tquot; );<br />t1.setName(quot; t1quot; );<br />t.setPriority(10);<br />t1.setPriority(-3);<br />t.start();<br />t1.start();<br />}<br />}<br />Options are A.t t1B.t1 tC.t tD.Compilation succeed but Runtime ExceptionAnswer :D is the correct answer. <br />Thread priorities are set using a positive integer, usually between 1 and 10. t1.setPriority(-3); throws java.lang.IllegalArgumentException. <br />Questions no -2 <br />What is the output for the below code ?<br />class A implements Runnable{<br />public void run(){<br />System.out.println(Thread.currentThread().getName());<br />} <br />}<br />1. public class Test {<br />2.public static void main(String... args) {<br />3.A a = new A();<br />4.Thread t = new Thread(a);<br />5.t.setName(quot; goodquot; );<br />6.t.start();<br />7.}<br />8. }<br />Options are A.goodB.nullC.Compilation fails with an error at line 5D.Compilation succeed but Runtime ExceptionAnswer :A is the correct answer. <br />Thread.currentThread().getName() return name of the current thread. <br />Questions no -3 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String[] args) {<br />Boolean expr = true;<br />if (expr) {<br />System.out.println(quot; truequot; );<br />} else {<br />System.out.println(quot; falsequot; );<br />}<br />}<br />}<br />options<br />A)true<br />B)Compile Error - can't use Boolean object in if().<br />C)false<br />D)Compile Properly but Runtime Exception.<br />Correct answer is : A<br />Explanations : In the if statement, condition can be Boolean object in jdk1.5 and jdk1.6.<br />In the previous version only boolean is allowed.<br />Questions no -4 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String[] args) {<br />List<Integer> list = new ArrayList<Integer>(); <br />list.add(0, 59);<br />int total = list.get(0);<br />System.out.println(total);<br />}<br />}<br />options<br />A)59<br />B)Compile time error, because you have to do int total = ((Integer)(list.get(0))).intValue();<br />C)Compile time error, because can't add primitive type in List.<br />D)Compile Properly but Runtime Exception.<br />Correct answer is : A<br />Explanations :Manual conversion between primitive types (such as an int) and wrapper classes <br />(such as Integer) is necessary when adding a primitive data type to a collection in jdk1.4 but<br />The new autoboxing/unboxing feature eliminates this manual conversion in jdk 1.5 and jdk 1.6.<br />Questions no -3 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String[] args) {<br />Integer i = null;<br />int j = i;<br />System.out.println(j);<br />}<br />}<br />options<br />A)0<br />B)Compile with error <br />C)null<br />D)NullPointerException<br />Correct answer is : D<br />Explanations :An Integer expression can have a null value. If your program tries to autounbox null, it will throw a NullPointerException.<br />Questions no -4 <br />What is the output for the below code ?<br />public class Outer {<br />private int a = 7;<br /> <br /> class Inner {<br /> public void displayValue() {<br /> System.out.println(quot; Value of a is quot; + a);<br /> }<br /> }<br />}<br />public class Test {<br />public static void main(String... args) throws Exception {<br />Outer mo = new Outer(); <br /> Outer.Inner inner = mo.new Inner();<br /> inner.displayValue();<br />}<br />}<br />options<br />A)Value of a is 7<br />B)Compile Error - not able to access private member.<br />C)Runtime Exception<br />D)Value of a is 8<br />Correct answer is : A<br />Explanations : An inner class instance can never stand alone without a direct relationship to an instance of the outer class.<br />you can access the inner class is through a live instance of the outer class.<br />Inner class can access private member of the outer class.<br />Questions no -5 <br />What is the output for the below code ?<br />public class B {<br />public String getCountryName(){<br />return quot; USAquot; ;<br />}<br />public StringBuffer getCountryName(){<br />StringBuffer sb = new StringBuffer();<br />sb.append(quot; UKquot; );<br />return sb;<br />}<br />public static void main(String[] args){<br />B b = new B();<br />System.out.println(b.getCountryName().toString());<br />}<br />}<br />options<br />A)Compile with error<br />B)USA<br />C)UK<br />D) Runtime Exception<br />Correct answer is : A<br />Explanations : You cannot have two methods in the same class with signatures that only differ by return type.<br />Questions no -6<br />What is the output for the below code ?<br />public class C {<br />}<br />public class D extends C{<br />}<br />public class A {<br />public C getOBJ(){<br />System.out.println(quot; class A - return Cquot; );<br />return new C();<br />}<br />}<br />public class B extends A{<br />public D getOBJ(){<br />System.out.println(quot; class B - return Dquot; );<br />return new D();<br />}<br />}<br />public class Test {<br />public static void main(String... args) {<br /> A a = new B();<br /> a.getOBJ();<br /> }<br />}<br />options<br />A)Compile with error - Not allowed to override the return type of a method with a subtype of the original type.<br />B)class A - return C<br />C)class B - return D<br />D) Runtime Exception<br />Correct answer is : C<br />Explanations : From J2SE 5.0 onwards. You are now allowed to override the return type of a method with a subtype of the original type.<br />Questions no -7<br />What is the output for the below code ?<br />public class A {<br />public String getName() throws ArrayIndexOutOfBoundsException{<br />return quot; Name-Aquot; ;<br />}<br />}<br />public class C extends A{<br />public String getName() throws Exception{<br />return quot; Name-Cquot; ;<br />}<br />}<br />public class Test {<br />public static void main(String... args) {<br />A a = new C();<br />a.getName();<br />}<br />}<br />options<br />A)Compile with error<br />B)Name-A<br />C)Name-C<br />D)Runtime Exception<br />Correct answer is : A<br />Explanations : Exception Exception is not compatible with throws clause in A.getName().<br />Overridden method should throw only same or sub class of the exception thrown by super class method.<br />Questions no -8 <br />What is the output for the below code ?<br />import java.util.regex.Matcher;<br />import java.util.regex.Pattern;<br />public class Test {<br />public static void main(String... args) {<br /> <br />Pattern p = Pattern.compile(quot; a*bquot; );<br />Matcher m = p.matcher(quot; bquot; );<br />boolean b = m.matches();<br />System.out.println(b);<br />}<br />}<br />options<br />A)true<br />B)Compile Error<br />C)false<br />D)b<br />Correct answer is : A<br />Explanations : a*b means quot; aquot; may present zero or more time and quot; bquot; should be present once.<br />Questions no -9 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br /> <br />String input = quot; 1 fish 2 fish red fish blue fishquot; ;<br />Scanner s = new Scanner(input).useDelimiter(quot; s*fishs*quot; );<br />System.out.println(s.nextInt());<br />System.out.println(s.nextInt());<br />System.out.println(s.next());<br />System.out.println(s.next());<br />s.close(); <br />}<br />}<br />options<br />A)1 2 red blue<br />B)Compile Error - because Scanner is not defind in java.<br />C)1 fish 2 fish red fish blue fish<br />D)1 fish 2 fish red blue fish<br />Correct answer is : A<br />Explanations : java.util.Scanner is a simple text scanner which can parse primitive types and strings using regular expressions.<br />Questions no -10 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br /> <br />Pattern p = Pattern.compile(quot; a{3}b?c*quot; );<br />Matcher m = p.matcher(quot; aaabquot; );<br />boolean b = m.matches();<br />System.out.println(b);<br />}<br />}<br />options<br />A)true<br />B)Compile Error <br />C)false<br />D)NullPointerException<br />Correct answer is : A<br />Explanations :<br />X? X, once or not at all <br />X* X, zero or more times <br />X+ X, one or more times <br />X{n} X, exactly n times <br />X{n,} X, at least n times <br />X{n,m} X, at least n but not more than m times<br />Questions no -11 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br /> <br />Pattern p = Pattern.compile(quot; a{1,3}b?c*quot; );<br />Matcher m = p.matcher(quot; aaabquot; );<br />boolean b = m.matches();<br />System.out.println(b);<br />}<br />}<br />options<br />A)true<br />B)Compile Error <br />C)false<br />D)NullPointerException<br />Correct answer is : A<br />Explanations :<br />X? X, once or not at all <br />X* X, zero or more times <br />X+ X, one or more times <br />X{n} X, exactly n times <br />X{n,} X, at least n times <br />X{n,m} X, at least n but not more than m times<br />Questions no -12 <br />What is the output for the below code ?<br />public class A {<br />public A() {<br /> System.out.println(quot; Aquot; );<br /> }<br />}<br />public class B extends A implements Serializable {<br />public B() {<br /> System.out.println(quot; Bquot; );<br /> }<br />}<br />public class Test {<br />public static void main(String... args) throws Exception {<br />B b = new B();<br /> <br /> ObjectOutputStream save = new ObjectOutputStream(new FileOutputStream(quot; datafilequot; ));<br /> save.writeObject(b); <br /> save.flush(); <br /> <br /> ObjectInputStream restore = new ObjectInputStream(new FileInputStream(quot; datafilequot; ));<br /> B z = (B) restore.readObject();<br /> <br />}<br />}<br />options<br />A)A B A<br />B)A B A B<br />C)B B<br />D)A B<br />Correct answer is : A<br />Explanations :On the time of deserialization , the Serializable object not create new object. So constructor of class B does not called. <br />A is not Serializable object so constructor is called.<br />Questions no -13 <br />What is the output for the below code ?<br />public class A {}<br />public class B implements Serializable {<br />A a = new A();<br />public static void main(String... args){<br />B b = new B();<br />try{<br />FileOutputStream fs = new FileOutputStream(quot; b.serquot; );<br />ObjectOutputStream os = new ObjectOutputStream(fs);<br />os.writeObject(b);<br />os.close();<br />}catch(Exception e){<br />e.printStackTrace();<br />}<br />}<br />}<br />options<br />A)Compilation Fail<br />B)java.io.NotSerializableException: Because class A is not Serializable.<br />C)Run properly<br />D)Compilation Fail : Because class A is not Serializable.<br />Correct answer is : B<br />Explanations :It throws java.io.NotSerializableException:A Because class A is not Serializable.<br />When JVM tries to serialize object B it will try to serialize A also because (A a = new A()) is instance variable of Class B.<br />So thows NotSerializableException.<br />Questions no -14 <br />What is the output for the below code running in the same JVM?<br />public class A implements Serializable {<br />transient int a = 7;<br /> static int b = 9;<br />}<br />public class B implements Serializable {<br />public static void main(String... args){<br />A a = new A();<br />try {<br /> ObjectOutputStream os = new ObjectOutputStream(<br /> new FileOutputStream(quot; test.serquot; ));<br /> os.writeObject(a); <br /> os. close();<br /> System.out.print( + + a.b + quot; quot; );<br /> ObjectInputStream is = new ObjectInputStream(new FileInputStream(quot; test.serquot; ));<br /> A s2 = (A)is.readObject();<br /> is.close();<br /> System.out.println(s2.a + quot; quot; + s2.b);<br /> } catch (Exception x) <br /> {<br /> x.printStackTrace();<br /> }<br />}<br />}<br />options<br />A)9 0 9<br />B)9 7 9<br />C)0 0 0<br />D)0 7 0<br />Correct answer is : A<br />Explanations :transient variables are not serialized when an object is serialized.<br />In the case of static variable you can get the values in the same JVM. <br />Questions no -15 <br />What is the output for the below code ?<br />public enum Test {<br />BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45);<br />private int hh;<br />private int mm;<br />Test(int hh, int mm) {<br />assert (hh >= 0 && hh <= 23) : quot; Illegal hour.quot; ;<br />assert (mm >= 0 && mm <= 59) : quot; Illegal mins.quot; ;<br />this.hh = hh;<br />this.mm = mm;<br />}<br />public int getHour() {<br />return hh;<br />}<br />public int getMins() {<br />return mm;<br />}<br />public static void main(String args[]){<br />Test t = new BREAKFAST;<br />System.out.println(t.getHour() +quot; :quot; +t.getMins());<br />}<br />}<br />options<br />A)7:30<br />B)Compile Error - an enum cannot be instantiated using the new operator.<br />C)12:50<br />D)19:45<br />Correct answer is : B<br />Explanations : As an enum cannot be instantiated using the new operator, the constructors cannot be called explicitly.<br />You have to do like <br />Test t = BREAKFAST;<br />Questions no -16 <br />What is the output for the below code ?<br />public class Test {<br />enum Day {<br />MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY<br />}<br />enum Month {<br />JAN, FEB<br />}<br />public static void main(String[] args) {<br />int[] freqArray = { 12, 34, 56, 23, 5, 13, 78 };<br />// Create a Map of frequencies<br />Map<Day, Integer> ordinaryMap = new HashMap<Day, Integer>();<br />for (Day day : Day.values()) {<br />ordinaryMap.put(day, freqArray[day.ordinal()]);<br />}<br />// Create an EnumMap of frequencies<br />EnumMap<Day, Integer> frequencyEnumMap = new EnumMap<Day, Integer>(ordinaryMap);<br />// Change some frequencies<br />frequencyEnumMap.put(null, 100);<br />System.out.println(quot; Frequency EnumMap: quot; + frequencyEnumMap);<br />}<br />}<br />options<br />A)Frequency EnumMap: {MONDAY=12, TUESDAY=34, WEDNESDAY=56, THURSDAY=23, FRIDAY=5, SATURDAY=13, SUNDAY=78}<br />B)Compile Error <br />C)NullPointerException<br />D)Frequency EnumMap: {MONDAY=100, TUESDAY=34, WEDNESDAY=56, THURSDAY=23, FRIDAY=5, SATURDAY=13, SUNDAY=123}<br />Correct answer is : C<br />Explanations : The null reference as a key is NOT permitted.<br />Questions no -17 <br />public class EnumTypeDeclarations {<br />public void foo() {<br />enum SimpleMeal { <br />BREAKFAST, LUNCH, DINNER <br />}<br />}<br />}<br />Is the above code Compile without error ?<br />options<br />A)Compile without error<br />B)Compile with error<br />C)Compile without error but Runtime Exception<br />D)Compile without error but Enum Exception<br />Correct answer is : B<br />Explanations :<br />An enum declaration is a special kind of class declaration:<br />a) It can be declared at the top-level and as static enum declaration. <br />b) It is implicitly static, i.e. no outer object is associated with an enum constant. <br />c) It is implicitly final unless it contains constant-specific class bodies, but it can implement interfaces. <br />d) It cannot be declared abstract unless each abstract method is overridden in the constant-specific class body of every enum constant. <br />e) Local (inner) enum declaration is NOT OK! <br />Here in<br />public void foo() {<br />enum SimpleMeal { <br />BREAKFAST, LUNCH, DINNER <br />}<br />}<br />enum declaration is local within method so compile time error.<br />Questions no -18 <br />What is the output for the below code ?<br />public enum Test {<br />int t;<br />BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45);<br />private int hh;<br />private int mm;<br />Test(int hh, int mm) {<br />assert (hh >= 0 && hh <= 23) : quot; Illegal hour.quot; ;<br />assert (mm >= 0 && mm <= 59) : quot; Illegal mins.quot; ;<br />this.hh = hh;<br />this.mm = mm;<br />}<br />public int getHour() {<br />return hh;<br />}<br />public int getMins() {<br />return mm;<br />}<br />public static void main(String args[]){<br />Test t = BREAKFAST;<br />System.out.println(t.getHour() +quot; :quot; +t.getMins());<br />}<br />}<br />options<br />A)7:30<br />B)Compile Error <br />C)12:15<br />D)19:45<br />Correct answer is : B<br />Explanations : The enum constants must be declared before any other declarations in an enum type.<br />In this case compile error because of declaration int t; before enum declaration.<br />Questions no -19 <br />What is the output for the below code ?<br />public class B extends Thread{<br />public static void main(String argv[]){<br />B b = new B();<br />b.run();<br />} <br />public void start(){<br />for (int i = 0; i < 10; i++){<br />System.out.println(quot; Value of i = quot; + i); <br />} <br />}<br />}<br />options<br />A)A compile time error indicating that no run method is defined for the Thread class<br />B)A run time error indicating that no run method is defined for the Thread class<br />C)Clean compile and at run time the values 0 to 9 are printed out<br />D)Clean compile but no output at runtime<br />Correct answer is : D<br />Explanations : This is a bit of a sneaky one as I have swapped around the names of the methods you need to define and call when running a thread. If the for loop were defined in a method called public void run() and the call in the main method had been to b.start() The list of values from 0 to 9 would have been output.<br />Questions no -20 <br />What is the output for the below code ?<br />public class Test extends Thread{<br /> static String sName = quot; goodquot; ;<br /> public static void main(String argv[]){<br /> Test t = new Test();<br /> t.nameTest(sName);<br /> System.out.println(sName);<br /> <br /> }<br /> public void nameTest(String sName){<br /> sName = sName + quot; idea quot; ;<br /> start();<br /> }<br /> public void run(){<br /> <br /> for(int i=0;i < 4; i++){<br /> sName = sName + quot; quot; + i;<br /> <br /> }<br /> }<br />}<br />options<br />A)good<br />B)good idea<br />C)good idea good idea<br />D)good 0 good 0 1<br />Correct answer is : A<br />Explanations : Change value in local methods wouldn’t change in global in case of String ( because String object is immutable).<br />Questions no -21 <br />What is the output for the below code ?<br />public class Test{<br />public static void main(String argv[]){<br />Test1 pm1 = new Test1(quot; Onequot; );<br />pm1.run();<br />Test1 pm2 = new Test1(quot; Twoquot; );<br />pm2.run();<br />}<br />}<br />class Test1 extends Thread{<br />private String sTname=quot; quot; ;<br />Test1(String s){<br />sTname = s;<br />}<br />public void run(){<br />for(int i =0; i < 2 ; i++){<br />try{<br /> sleep(1000);<br />}catch(InterruptedException e){}<br />yield();<br />System.out.println(sTname);<br />}<br />}<br />}<br />options<br />A)Compile error<br />B)One One Two Two<br />C)One Two One Two<br />D)One Two<br />Correct answer is : B<br />Explanations : If you call the run method directly it just acts as any other method and does not return to the calling code until it has finished. executing<br />Questions no -22 <br />What is the output for the below code ?<br />public class Test extends Thread{<br /> public static void main(String argv[]){<br /> Test b = new Test();<br /> b.start();<br /> }<br /> public void run(){ <br /> System.out.println(quot; Runningquot; );<br /> }<br />}<br />options<br />A)Compilation clean and run but no output<br />B)Compilation and run with the output quot; Runningquot; <br />C)Compile time error with complaint of no Thread import<br />D)Compile time error with complaint of no access to Thread package<br />Correct answer is : B<br />Explanations :<br />The Thread class is part of the core java.lang package and does not need any explicit import statement.<br />Questions no -23 <br />What is the output for the below code ?<br />public class Tech {<br /> public void tech() {<br /> System.out.println(quot; Techquot; );<br /> }<br />}<br />public class Atech {<br />Tech a = new Tech() { <br /> public void tech() {<br /> System.out.println(quot; anonymous techquot; );<br /> }<br /> };<br /> <br /> public void dothis() {<br /> a.tech(); <br /> <br /> }<br />public static void main(String... args){<br />Atech atech = new Atech();<br />atech.dothis();<br />}<br />options<br />A)anonymous tech<br />B)Compile Error <br />C)Tech<br />D)anonymous tech Tech<br />Correct answer is : A<br />Explanations : This is anonymous subclass of the specified class type.<br />Anonymous inner class ( anonymous subclass ) overriden the Tech super class of tech() method.<br />Therefore Subclass method will get called.<br />Questions no -24 <br />What is the output for the below code ?<br />public class Outer {<br /> private String x = quot; Outer variablequot; ;<br /> void doStuff() {<br /> String z = quot; local variablequot; ;<br /> class Inner {<br /> public void seeOuter() {<br /> System.out.println(quot; Outer x is quot; + x);<br /> System.out.println(quot; Local variable z is quot; + z); <br /> } <br /> } <br /> } <br /> <br /> <br />}<br />options<br />A)Outer x is Outer variable.<br />B)Compile Error <br />C)Local variable z is local variable.<br />D)Outer x is Outer variable Local variable z is local variable<br />Correct answer is : B<br />Explanations : Cannot refer to a non-final variable z inside an inner class defined in a different method.<br />Questions no -25<br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br />for(int i = 2; i < 4; i++)<br /> for(int j = 2; j < 4; j++)<br /> assert i!=j : i; <br />}<br />}<br />options<br />A)The class compiles and runs, but does not print anything.<br />B)The number 2 gets printed with AssertionError<br />C)The number 3 gets printed with AssertionError<br />D)compile error<br />Correct answer is : B<br />Explanations : When i and j are both 2, assert condition is false, and AssertionError gets generated. <br />Questions no -26<br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br />for(int i = 2; i < 4; i++)<br /> for(int j = 2; j < 4; j++)<br />if(i < j)<br /> assert i!=j : i; <br />}<br />}<br />options<br />A)The class compiles and runs, but does not print anything.<br />B)The number 2 gets printed with AssertionError<br />C)The number 3 gets printed with AssertionError<br />D)compile error<br />Correct answer is : A<br />Explanations : When if condition returns true, the assert statement also returns true.<br />Hence AssertionError not generated.<br />Questions no -26 <br />What is the output for the below code ?<br />public class NameBean {<br />private String str;<br />NameBean(String str ){<br />this.str = str;<br />}<br />public String toString() {<br />return str;<br />}<br />}<br />import java.util.HashSet;<br />public class CollClient {<br />public static void main(String ... sss) {<br />HashSet myMap = new HashSet();<br />String s1 = new String(quot; dasquot; );<br />String s2 = new String(quot; dasquot; );<br />NameBean s3 = new NameBean(quot; abcdefquot; );<br />NameBean s4 = new NameBean(quot; abcdefquot; );<br />myMap.add(s1);<br />myMap.add(s2);<br />myMap.add(s3);<br />myMap.add(s4);<br />System.out.println(myMap);<br />}<br />}<br />options<br />A)das abcdef abcdef<br />B)das das abcdef abcdef<br />C)das abcdef<br />D)abcdef abcdef<br />Correct answer is : A<br />Explanations : Need to implement 'equals' and 'hashCode' methods to get unique Set for user defind objects(NameBean).<br />String object internally implements 'equals' and 'hashCode' methods therefore Set only stored one value.<br />Questions no -27 <br />Synchronized resizable-array implementation of the List interface is _____________?<br />options<br />A)Vector<br />B)ArrayList<br />C)Hashtable<br />D)HashMap<br />Correct answer is : A<br />Explanations : Vector implements List, RandomAccess - Synchronized resizable-array implementation of the List interface with additional quot; legacy methods.quot; <br />Questions no -28 <br />What is the output for the below code ?<br />public class Test {<br /> <br /> public static void main(String argv[]){<br /> <br /> ArrayList list = new ArrayList(); <br /> ArrayList<String> listStr = list; <br /> ArrayList<StringBuffer> listBuf = list; <br /> listStr.add(0, quot; Helloquot; ); <br /> StringBuffer buff = listBuf.get(0); <br /> System.out.println(buff.toString());<br /> }<br />}<br />options<br />A)Hello<br />B)Compile error<br />C)java.lang.ClassCastException<br />D)null<br />Correct answer is : C<br />Explanations : java.lang.String cannot be cast to java.lang.StringBuffer at the code StringBuffer buff = listBuf.get(0); <br />So thows java.lang.ClassCastException.<br />Questions no -29 <br />What is the output for the below code ?<br />import java.util.LinkedList;<br />import java.util.Queue;<br />public class Test {<br />public static void main(String... args) {<br /> <br />Queue<String> q = new LinkedList<String>();<br /> q.add(quot; newyorkquot; );<br /> q.add(quot; caquot; );<br /> q.add(quot; texasquot; );<br /> show(q);<br /> }<br /> public static void show(Queue q) {<br /> q.add(new Integer(11));<br /> while (!q.isEmpty ( ) )<br /> System.out.print(q.poll() + quot; quot; );<br /> }<br />}<br />options<br />A)Compile error : Integer can't add<br />B)newyork ca texas 11<br />C)newyork ca texas<br />D)newyork ca <br />Correct answer is : B<br />Explanations : <br /> q was originally declared as Queue<String>, But in show() method it is passed as an untyped Queue. nothing in the compiler or JVM prevents us from adding an Integer after that.<br /> If the show method signature is public static void show(Queue<String> q) than you can't add Integer, Only String allowed. But public static void show(Queue q) is untyped Queue so you can add Integer.<br /> poll() Retrieves and removes the head of this queue, or returns null if this queue is empty.<br />Questions no -30 <br />What is the output for the below code ?<br />public interface TestInf {<br /> int i =10;<br />}<br />public class Test {<br />public static void main(String... args) {<br />TestInf.i=12;<br />System.out.println(TestInf.i);<br />}<br />}<br />options<br />A)Compile with error<br />B)10<br />C)12<br />D) Runtime Exception<br />Correct answer is : A<br />Explanations : All the variables declared in interface is Implicitly static and final , therefore can't change the value.<br />Questions no -31 <br />What is the output for the below code ?<br />public class Test {<br /> static { int a = 5; }<br /> public static void main(String[] args){<br /> System.out.println(a);<br /> }<br /> }<br />options<br />A)Compile with error<br />B)5<br />C)0<br />D) Runtime Exception<br />Correct answer is : A<br />Explanations : A variable declared in a static initialiser is not accessible outside its enclosing block.<br />Questions no -32 <br />What is the output for the below code ?<br />class A {<br /> { System.out.print(quot; b1 quot; ); }<br /> public A() { System.out.print(quot; b2 quot; ); }<br />}<br />class B extends A {<br /> static { System.out.print(quot; r1 quot; ); }<br /> public B() { System.out.print(quot; r2 quot; ); }<br /> { System.out.print(quot; r3 quot; ); }<br /> static { System.out.print(quot; r4 quot; ); }<br />}<br />class C extends B {<br /> public static void main(String[] args) {<br /> System.out.print(quot; pre quot; );<br /> new C();<br /> System.out.println(quot; post quot; );<br /> }<br />}<br />options<br />A)r1 r4 pre b1 b2 r3 r2 post<br />B)r1 r4 pre b1 b2 post<br />C)r1 r4 pre b1 b2 post r3 r2<br />D)pre r1 r4 b1 b2 r2 r3 post<br />Correct answer is : A<br />Explanations : All static blocks execute first then blocks and constructor. <br />Blocks and constructor executes (super class block then super class constructor, sub class block then sub class constructor).<br />Sequence for static blocks is super class first then sub class.<br />Sequence for blocks is super class first then sub class.<br />Questions no -33 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) throws Exception {<br />Integer i = 34;<br />int l = 34;<br />if(i.equals(l)){<br />System.out.println(true);<br />}else{<br />System.out.println(false);<br />}<br />}<br />}<br />options<br />A)true<br />B)false<br />C)Compile Error<br />D) Runtime Exception<br />Correct answer is : A<br />Explanations : equals() method for the integer wrappers will only return true if the two primitive types and the two values are equal.<br />Questions no -34 <br />Which statement is true about outer class?<br />options<br />A)outer class can only declare public , abstract and final<br />B)outer class may be private<br />C)outer class can't be abstract<br />D)outer class can be static<br />Correct answer is : A<br />Explanations : outer class can only declare public , abstract and final.<br />Questions no -35 <br />What is the output for the below code ?<br />static public class Test {<br />public static void main(String[] args) {<br /> char c = 'a';<br /> switch(c){<br /> case 65:<br /> System.out.println(quot; onequot; );break;<br /> case 'a':<br /> System.out.println(quot; twoquot; );break;<br /> case 3:<br /> System.out.println(quot; threequot; );<br />}<br />}<br />}<br />options<br />A)one<br />B)two<br />C)Compile error - char can't be permitted in switch statement <br />D)Compile error - Illegal modifier for the class Test; only public, abstract & final are permitted.<br />Correct answer is : D<br />Explanations : outer class can only declare public , abstract and final.<br />Illegal modifier for the class Test; only public, abstract & final are permitted<br />Questions no -36<br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br />ArrayList<Integer> list = new ArrayList<Integer>();<br />list.add(1);<br />list.add(2);<br />list.add(3);<br />for(int i:list)<br />System.out.println(i);<br />}<br />}<br />options<br />A)1 2 3<br />B)Compile error , can't add primitive type in ArrayList<br />C)Compile error on for(int i:list) , Incorrect Syntax<br />D)0 0 0<br />Correct answer is : A<br />Explanations : JDK 1.5, 1.6 allows add primitive type in ArrayList and for(int i:list) syntax is also correct.<br />for(int i:list) is same as <br />for(int i=0; i < list.size();i++){<br />int a = list.get(i);<br />}<br />Questions no -37 <br />What is the output for the below code ?<br />public class SuperClass {<br />public int doIt(String str, Integer... data)throws ArrayIndexOutOfBoundsException{<br />String signature = quot; (String, Integer[])quot; ;<br />System.out.println(str + quot; quot; + signature);<br />return 1;<br />}<br />}<br />public class SubClass extends SuperClass{<br />public int doIt(String str, Integer... data) throws Exception<br />{<br />String signature = quot; (String, Integer[])quot; ;<br />System.out.println(quot; Overridden: quot; + str + quot; quot; + signature);<br />return 0;<br />}<br />public static void main(String... args)<br />{<br />SuperClass sb = new SubClass();<br />try{<br />sb.doIt(quot; helloquot; , 3);<br />}catch(Exception e){<br />}<br />}<br />}<br />options<br />A)Overridden: hello (String, Integer[])<br />B)hello (String, Integer[])<br />C)This code throws an Exception at Runtime<br />D)Compile with error<br />Correct answer is : D<br />Explanations : Exception Exception is not compatible with throws clause in SuperClass.doIt(String, Integer[]). <br />The same exception or subclass of that exception is allowed.<br />Questions no -38<br />What is the result of executing the following code, using the parameters 0 and 3 ?<br />public void divide(int a, int b) {<br />try {<br />int c = a / b;<br />} catch (Exception e) {<br />System.out.print(quot; Exception quot; );<br />} finally {<br />System.out.println(quot; Finallyquot; );<br />}<br />options<br />A)Prints out: Exception Finally<br />B)Prints out: Finally<br />C)Prints out: Exception<br />D)Compile with error<br />Correct answer is : B<br />Explanations : finally block always executed whether exception occurs or not. <br />0/3 = 0 Does not throws exception.<br />Questions no -39<br />Which of the below statement is true about Error?<br />options<br />A)An Error is a subclass of Throwable<br />B)An Error is a subclass of Exception<br />C)Error indicates serious problems that a reasonable application should not try to catch.<br />D)An Error is a subclass of IOException<br />Correct answer is : A and C<br />Explanations : An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.<br />Questions no -40<br />Which of the following is type of RuntimeException?<br />options<br />A)IOException<br />B)ArrayIndexOutOfBoundsException<br />C)Exception<br />D)Error<br />Correct answer is : B<br />Explanations : Below is the tree.<br />java.lang.Object<br /> java.lang.Throwable<br /> java.lang.Exception<br /> java.lang.RuntimeException<br /> java.lang.IndexOutOfBoundsException<br /> java.lang.ArrayIndexOutOfBoundsException<br />Questions no -41 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) throws Exception {<br /> File file = new File(quot; test.txtquot; ); <br /> System.out.println(file.exists());<br /> FileWriter fw = new FileWriter(file); <br /> System.out.println(file.exists());<br />}<br />}<br />options<br />A)true true<br />B)false false<br />C)false true<br />D)true false<br />Correct answer is : C<br />Explanations :Creating a new instance of the class File, you're not yet making an actual file, you're just creating a filename.<br />So file.exists() return false.<br />FileWriter fw = new FileWriter(file) do three things:<br />It created a FileWriter reference variable fw.<br />It created a FileWriter object, and assigned it to fw.<br />It created an actual empty file out on the disk.<br />So file.exists() return true.<br />Questions no -42 <br />When comparing java.io.BufferedWriter and java.io.FileWriter, which capability exist as a method in only one of two ?<br />options<br />A)closing the stream<br />B)flushing the stream<br />C)writting to the stream<br />D)writting a line separator to the stream<br />Correct answer is : D<br />Explanations :A newLine() method is provided in BufferedWriter which is not in FileWriter.<br />Questions no -43 <br />What is the output for the below code ?<br />public class Test{<br />public static void main(String[] args) {<br /> int i1=1;<br /> switch(i1){<br /> case 1:<br /> System.out.println(quot; onequot; );<br /> case 2:<br /> System.out.println(quot; twoquot; );<br /> case 3:<br /> System.out.println(quot; threequot; );<br />}<br />}<br />}<br />options<br />A)one two three<br />B)one<br />C)one two<br />D)Compile error.<br />Correct answer is : A<br />Explanations : There is no break statement in case 1 so it causes the below case statements to execute regardless of their values.<br />Questions no -44 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String[] args) {<br /> char c = 'a';<br /> switch(c){<br /> case 65:<br /> System.out.println(quot; onequot; );break;<br /> case 'a':<br /> System.out.println(quot; twoquot; );break;<br /> case 3:<br /> System.out.println(quot; threequot; );<br />}<br />}<br />}<br />options<br />A)one two three<br />B)one<br />C)two<br />D)Compile error - char can't be in switch statement.<br />Correct answer is : C<br />Explanations : Compile properly and print two.<br />Questions no -45 <br />What is the output for the below code ?<br />import java.util.NavigableMap;<br />import java.util.concurrent.ConcurrentSkipListMap;<br />public class Test {<br />public static void main(String... args) {<br /> <br />NavigableMap <Integer, String>navMap = new <br /> ConcurrentSkipListMap<Integer, String>();<br />navMap.put(4, quot; Aprilquot; );<br />navMap.put(5, quot; Mayquot; );<br />navMap.put(6, quot; Junequot; );<br />navMap.put(1, quot; Januaryquot; );<br />navMap.put(2, quot; Februaryquot; );<br />navMap.put(3, quot; Marchquot; );<br /> navMap.pollFirstEntry();<br /> navMap.pollLastEntry();<br /> navMap.pollFirstEntry();<br /> System.out.println(navMap.size());<br /> <br />}<br />}<br />options<br />A)Compile error : No method name like pollFirstEntry() or pollLastEntry()<br />B)3<br />C)6<br />D)4<br />Correct answer is : B<br />Explanations : <br /> pollFirstEntry() Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty.<br /> pollLastEntry() Removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.<br />Questions no -46<br />What is the output for the below code ?<br />import java.util.NavigableMap;<br />import java.util.concurrent.ConcurrentSkipListMap;<br />public class Test {<br />public static void main(String... args) {<br /> <br />NavigableMap <Integer, String>navMap = new <br /> ConcurrentSkipListMap<Integer, String>();<br /> System.out.print(navMap.lastEntry());<br /> <br />}<br />}<br />options<br />A)Compile error : No method name like lastEntry()<br />B)null<br />C)NullPointerException<br />D)0<br />Correct answer is : B<br />Explanations : lastEntry() Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.<br />Questions no -47<br />What is the output for the below code ?<br />import java.util.NavigableMap;<br />import java.util.concurrent.ConcurrentSkipListMap;<br />public class Test {<br />public static void main(String... args) {<br /> <br />NavigableMap<Integer, String>navMap = new <br /> ConcurrentSkipListMap<Integer, String>();<br />navMap.put(4, quot; Aprilquot; );<br />navMap.put(5, quot; Mayquot; );<br />navMap.put(6, quot; Junequot; );<br />navMap.put(1, quot; Januaryquot; );<br />navMap.put(2, quot; Februaryquot; );<br /> System.out.print(navMap.ceilingKey(3));<br /> <br /> <br />}<br />}<br />options<br />A)Compile error : No method name like ceilingKey()<br />B)null<br />C)NullPointerException<br />D)4<br />Correct answer is : D<br />Explanations : Returns the least key greater than or equal to the given key, or null if there is no such key. <br />In the above case : 3 is not a key so return 4 (least key greater than or equal to the given key).<br />Questions no -48<br />What is the output for the below code ?<br />import java.util.NavigableMap;<br />import java.util.concurrent.ConcurrentSkipListMap;<br />public class Test {<br />public static void main(String... args) {<br /> <br />NavigableMap<Integer, String>navMap = new <br /> ConcurrentSkipListMap<Integer, String>();<br />navMap.put(4, quot; Aprilquot; );<br />navMap.put(5, quot; Mayquot; );<br />navMap.put(6, quot; Junequot; );<br />navMap.put(1, quot; Januaryquot; );<br />navMap.put(2, quot; Februaryquot; );<br /> System.out.print(navMap.floorKey(3));<br /> <br /> <br />}<br />}<br />options<br />A)Compile error : No method name like floorKey()<br />B)null<br />C)NullPointerException<br />D)2<br />Correct answer is : D<br />Explanations : Returns the greatest key less than or equal to the given key, or null if there is no such key. <br />In the above case : 3 is not a key so return 2 (greatest key less than or equal to the given key).<br />Questions no -49 <br />What is the output for the below code ?<br />public class Test {<br />public static void main(String... args) {<br /> <br /> List<Integer> lst = new ArrayList<Integer>();<br /> lst.add(34);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(5);<br /> <br /> NavigableSet<Integer> nvset = new TreeSet(lst);<br /> System.out.println(nvset.tailSet(6));<br /> <br />}<br />}<br />options<br />A)Compile error : No method name like tailSet()<br />B)6 34<br />C)5<br />D)5 6 34<br />Correct answer is : B<br />Explanations : tailSet(6) Returns elements are greater than or equal to 6.<br />Questions no -50 <br />What is the output for the below code ?<br />import java.util.ArrayList;<br />import java.util.List;<br />import java.util.NavigableSet;<br />import java.util.TreeSet;<br />public class Test {<br />public static void main(String... args) {<br /> <br />List<Integer> lst = new ArrayList<Integer>();<br /> lst.add(34);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(6);<br /> lst.add(6);<br /> <br /> NavigableSet<Integer> nvset = new TreeSet(lst);<br /> nvset.pollFirst(); <br /> nvset.pollLast();<br /> System.out.println(nvset.size());<br /> <br />}<br />}<br />options<br />A)Compile error : No method name like pollFirst() or pollLast()<br />B)0<br />C)3<br />D)5<br />Correct answer is : B<br />Explanations : <br /> pollFirst() Retrieves and removes the first (lowest) element, or returns null if this set is empty.<br /> pollLast() Retrieves and removes the last (highest) element, or returns null if this set is empty.<br />Questions no -51<br />What is the output for the below code ?<br />import java.util.ArrayList;<br />import java.util.List;<br />import java.util.NavigableSet;<br />import java.util.TreeSet;<br />public class Test {<br />public static void main(String... args) {<br /> <br /> List<Integer> lst = new ArrayList<Integer>();<br /> lst.add(34);<br /> lst.add(6);<br /> lst.add(2);<br /> lst.add(8);<br /> lst.add(7);<br /> lst.add(10);<br /> <br /> NavigableSet<Integer> nvset = new TreeSet(lst);<br /> System.out.println(nvset.lower(6)+quot; quot; +nvset.higher(6)+ quot; quot; + nvset.lower(2));<br /> <br />}<br />}<br />options<br />A)1 2 7 10 34 null<br />B)2 7 null<br />C)2 7 34<br />D)1 2 7 10 34<br />Correct answer is : B<br />Explanations : <br /> lower() Returns the greatest element in this set strictly less than the given element, or null if there is no such element.<br /> higher() Returns the least element in this set strictly greater than the given element, or null if there is no such element.<br />Questions no -52<br />What is the output for the below code ?<br />import java.util.ArrayList;<br />import java.util.Iterator;<br />import java.util.List;<br />import java.util.NavigableSet;<br />import java.util.TreeSet;<br />public class Test {<br />public static void main(String... args) {<br /> <br /> List<Integer> lst = new ArrayList<Integer>();<br /> lst.add(34);<br /> lst.add(6);<br /> lst.add(2);<br /> lst.add(8);<br /> lst.add(7);<br /> lst.add(10);<br /> <br /> NavigableSet<Integer> nvset = new TreeSet(lst);<br /> System.out.println(nvset.headSet(10));<br /> <br />}<br />}<br />options<br />A)Compile error : No method name like headSet()<br />B)2, 6, 7, 8, 10<br />C)2, 6, 7, 8<br />D)34<br />Correct answer is : C<br />Explanations : <br /> headSet(10) Returns the elements elements are strictly less than 10.<br /> headSet(10,false) Returns the elements elements are strictly less than 10.<br /> headSet(10,true) Returns the elements elements are strictly less than or equal to 10.<br />Questions no -53 <br />What is the output for the below code ?<br />import java.io.Console;<br />public class Test {<br />public static void main(String... args) {<br /> <br />Console con = System.console();<br /> boolean auth = false;<br /> <br /> if (con != null)<br /> {<br /> int count = 0;<br /> do<br /> {<br /> String uname = con.readLine(null);<br /> char[] pwd = con.readPassword(quot; Enter %s's password: quot; , uname);<br /> <br /> con.writer().write(quot; quot; ); <br /> } while (!auth && ++count < 3);<br /> }<br /> <br />}<br />}<br />options<br />A)NullPointerException<br />B)It works properly<br />C)Compile Error : No readPassword() method in Console class.<br />D)null<br />Correct answer is : A<br />Explanations : passing a null argument to any method in Console class will cause a NullPointerException to be thrown.<br />