http://www.javagenious.com/forum/index.php?PHPSESSID=67ddee677841675f48643995dfeb79fc&topi c=2.

0

SCJP 1.6(CX-310-065) Exam Pattern : Exam type: Exam type: Multiple choice and drag and drop Number of questions: 72 Pass score: 65% (47 of 72 questions) Time limit: 210 minutes
Section 1: Declarations, Initialization and Scoping Section 2: Flow Control Section 3: API Contents Section 4: Concurrency Section 5: OO Concepts Section 6: Collections / Generics Section 7: Fundamentals

Vinsys IT Services 1st main BTM layout 100ft Ringroad, Near Friends resturant, Bangalore 5600068 Karnataka Call Us:080-41550745. Mobile : +91 9986074882. Email us at: vikram.patil@vinsys.in. Website :www.vinsys.in

Section 1: Declarations, Initialization and Scoping -------------------------------------------------------------------------------------------------------------------------------------------------------------------y Develop code that declares classes(including abstract and all types of nested classes), interfaces, enums, and includes the appropriate use of package and import statements (including static imports). Develop code that declares an interface and that implements or extends one or more interfaces. Develop code that declares an abstract class. Develop code that extends an abstract class. Develop code that declares, initializes, and uses primitives, arrays, enums, and objects as static, instance, and local variables. Also, use legal identifiers for variable names. Given a code example, determine if a method is correctly overriding or overloading another method, and identify legal return values (including covariant returns), for the method.

y

y

SureSuccess 3rd Floor, Siteno. 8/2 (OldNo9) Brook Field Main Road, Near HDFC Bank,HyperCity Mall Bangalore 560037 Karnataka Call Us:080 4227 4295. Mobile : +91 8105820111. Email us at: service@getsuresuccess.com. Website :www.getsuresuccess.com

y

Given a set of classes and superclasses, develop constructors for one or more of the classes. Given a class declaration, determine if a default constructor will be created, and if so, determine the behavior of that constructor. Given a nested or non-nested class listing, write code to instantiate the class.

Section 2: Flow Control

CMS Institute Jayanagar CMS Info Systems Pvt Ltd. # 610 Vandna Arcade , 3rd Flore 10th A main Road Jayanagar 4th Block Bangalore 560011 (Near to Masjid) Ph: 9986690134 Mail: ajay_singh@cmsinstitute.co.in

y

Develop code that implements an if or switch

y

y

y

y

y

statement; and identify legal argument types for these statements. Develop code that implements all forms of loops and iterators, including the use of for, the enhanced for loop (for-each), do, while, labels, break, and continue; and explain the values taken by loop counter variables during and after loop execution. Develop code that makes use of assertions, and distinguish appropriate from inappropriate uses of assertions. Develop code that makes use of exceptions and exception handling clauses (try, catch, finally), and declares methods and overriding methods that throw exceptions. Recognize the effect of an exception arising at a specified point in a code fragment. Note that the exception may be a runtime exception, a checked exception, or an error. Recognize situations that will result in any of the following being thrown: ArrayIndexOutOfBoundsException,ClassCastExceptio n, IllegalArgumentException, IllegalStateException, NullPointerException, NumberFormatException, AssertionError, ExceptionInInitializerError, StackOverflowError or NoClassDefFoundError. Understand which of these are thrown by the virtual machine and recognize situations in which others should be thrown programatically.

1) Asna Institute of Hardware Technology Pvt. Ltd. #346/36, 1st Florr, H.M.T Main Road, Opps.Subbaiah Hospital, Mathikere, Bangalore-560054 Phone: 080-23378342 site code: II127 2) NAISSANCE INFOTECH 307 ,GROUND FLOOR, 18TH CROSS 6TH MAIN, MALLESWARAM BANGALORE, Karnataka 560055 Phone: 080-2344 9427/28 Site Code: II66 3) NIIT LTD Vijayanagar Address : No. 2934/E & 2935/E, III Floor,Magadi Rd, Vijayanagar II Stage, Bangalore - 560 040 Landline : 080-30582764 Mobile : +91 99641 44096 4) MICRO ACADEMY (I) PVT. LTD. #72, Keonics Electronics City Hosur Main Road BANGALORE, Karnataka 560100 Phone: 080-51381749 Site Code: IID68 5) IIHT LIMITED-INFANTRY ROAD-BANGALORE 63, OPP. SALEEH AHMED INFANTRY ROAD BANGALORE, Karnataka 560001 Phone: 080-25598351

Section 3: API Contents

y

y

y

y

Develop code that uses the primitive wrapper classes (such as Boolean, Character, Double, Integer, etc.), and/or autoboxing & unboxing. Discuss the differences between the String, StringBuilder, and StringBuffer classes. Given a scenario involving navigating file systems, reading from files, writing to files, or interacting with the user, develop the correct solution using the following classes (sometimes in combination), from java.io: BufferedReader, BufferedWriter, File, FileReader, FileWriter, PrintWriter, and Console. Use standard J2SE APIs in the java.text package to correctly format or parse dates, numbers, and currency values for a specific locale; and, given a scenario, determine the appropriate methods to use if you want to use the default locale or a specific locale. Describe the purpose and use of the java.util.Locale class. Write code that uses standard J2SE APIs in the java.util and java.util.regex packages to format or parse strings or streams. For strings, write code that

uses the Pattern and Matcher classes and the String.split method. Recognize and use regular expression patterns for matching (limited to: . (dot), * (star), + (plus), ?, \d, \s, \w, [], ()). The use of *, +, and ? will be limited to greedy quantifiers, and the parenthesis operator will only be used as a grouping mechanism, not for capturing content during matching. For streams, write code using the Formatter and Scanner classes and the PrintWriter.format/printf methods. Recognize and use formatting parameters (limited to: %b, %c, %d, %f, %s) in format strings.

Site Code: IIF23

6) R.C.S. EDUCATION PVT LTD 127, 4TH FLOOR ANCHORAGE COURT OPP BRIGADE TOWERS BRIGADE ROAD BANGALORE, Karnataka 560025 Phone: 080-25361911 Site Code: IIF16

Section 4: Concurrency

y

y

y

Write code to define, instantiate, and start new threads using both java.lang.Thread and java.lang.Runnable. Recognize the states in which a thread can exist, and identify ways in which a thread can transition from one state to another. Given a scenario, write code that makes appropriate use of object locking to protect static or instance variables from concurrent access problems.

7) Q-SOFT Systems & Solutions (P) Ltd. 252, First Floor Kanakapura Road Jaya Nagar 7th Block Bangalore, Karnataka 560 082 Phone: 26340507/26639207 Site Code: IIF51

Section 5: OO Concepts

y

y

y

y

y

Develop code that implements tight encapsulation, loose coupling, and high cohesion in classes, and describe the benefits. Given a scenario, develop code that demonstrates the use of polymorphism. Further, determine when casting will be necessary and recognize compiler vs. runtime errors related to object reference casting. Explain the effect of modifiers on inheritance with respect to constructors, instance or static variables, and instance or static methods. Given a scenario, develop code that declares and/or invokes overridden or overloaded methods and code that declares and/or invokes superclass, or overloaded constructors. Develop code that implements "is-a" and/or "has-a" relationships.

8) NCT TRAINING PVT LTD NO 2 2ND FLOOR MUNISWAMAPPA RD NEXT TO POLICE STATION J. C. NAGAR BANGALORE, Karnataka 560006 Phone: 080-41285393 Site Code: IIF79

Section 6: Collections / Generics

9) NEW HORIZON INDIA LIMITED-DICKENSEN ROAD-BANGALORE N-101, NORTH BLOCK, MANIPAL CENTER 47 DICKENSEN ROAD BANGALORE, Karnataka 560041 Phone: 25595380 Site Code: IIG19

y

y

y

y

y

Given a design scenario, determine which collection classes and/or interfaces should be used to properly implement that design, including the use of the Comparable interface. Distinguish between correct and incorrect overrides of corresponding hashCode and equals methods, and explain the difference between == and the equals method. Write code that uses the generic versions of the Collections API, in particular, the Set, List, and Map interfaces and implementation classes. Recognize the limitations of the non-generic Collections API and how to refactor code to use the generic versions. Write code that uses the NavigableSet and NavigableMap interfaces. Develop code that makes proper use of type parameters in class/interface declarations, instance variables, method arguments, and return types; and write generic methods or methods that make use of wildcard types and understand the similarities and differences between these two approaches. Use capabilities in the java.util package to write code to manipulate a list by sorting, performing a binary search, or converting the list to an array. Use capabilities in the java.util package to write code to manipulate an array by sorting, performing a binary search, or converting the array to a list. Use the java.util.Comparator and java.lang.Comparable interfaces to affect the sorting of lists and arrays. Furthermore, recognize the effect of the "natural ordering" of primitive wrapper classes and java.lang.String on sorting.

10) NEW HORIZON INDIA LIMITED-DICKENSEN ROAD-BANGALORE UNIT #401, MONEY POINT 4TH FLOOR, #59 KH ROAD (DOUBLE ROAD) EMERALD SYSTEMS BANGALORE, Karnataka 560027 Phone: 080-22483919 Site Code: IIG2 11) iDOMAINS TECHNOLOGIES No.65, First Floor,KHB Colony, 2nd A Cross,5th Block, Koramangala,Behind Wipro K1 Building,Near JyotiNivas Coleg BANGALORE, Karnataka 560095 Phone: 4121613041102030 Site Code: IIG24 12) INFOSYS TECHNOLOGIES LTD( Only for Infosys Employees) ELECTRONICS CITY HOSUR ROAD BANGALORE, Karnataka Phone: 080-28520261 Site Code: IIG4 13) GALAXY INFORMATION TECHNOLOGIES #3346/A,1-FLOOR,13TH CROSS BANASHANKARI 2ND STAGE BANGALORE, Karnataka 560070 Phone: 80-55333187 Site Code: IIG60

Section 7: Fundamentals

y

y y

y

Given a code example and a scenario, write code that uses the appropriate access modifiers, package declarations, and import statements to interact with (through access or inheritance) the code in the example. Given an example of a class and a command-line, determine the expected runtime behavior. Determine the effect upon object references and primitive values when they are passed into methods that perform assignments or other modifying operations on the parameters. Given a code example, recognize the point at which an object becomes eligible for garbage collection, determine what is and is not guaranteed by the garbage collection system, and recognize the behaviors of the Object.finalize() method.

Karnataka . Write code that determines the equality of two objects or two primitives. and the conditional operator ( ? : ). &&. Write code that correctly applies the appropriate operators including assignment operators (limited to: =.3RD BLOCK (OPP. >. the instanceof operator. ++. !=). DOMLUR (ABOVE HAIKU HONDA SHOWROOM) BANGALORE. Karnataka 560080 Phone: 41137700/01/02 Site Code: IIG98 17) LEARNING LABS PVT LIMITED LEARNING LABS PVT LIMITED # 1. %. >=. arithmetic operators (limited to: +. -=).TO COSMOPOLITAN CLUB) JAYANAGAR BANGALORE. *. /.NO 296 2ND FLOOR 22ND CROSS. Given a code example and a classpath. BANGALORE. ESTEEM PLAZA ABOVE COFFEE DAY SADASHIVNAGAR. determine whether the classpath will allow the code to compile successfully. HIRANYA COMPLEX.KESHAVA KRUPA.4TH BLOCK JAYANAGAR BANGALORE. logical operators (limited to: &. to produce a desired result. Karnataka 560011 Phone: 080-30934868 Site Code: IIG80 15) IIHT LTD JAYANAGAR-BANGALORE -(FRANCHISEE) SOLUTIONS INTEGRATEDFRANCHISE #74. 14) DAKSHIN TECHNOLOGIES GVS COMPLEX .10-M 30TH CROSS. +=. -. AIRPORT ROAD. |. construct the appropriate directory structure for that class. ==. --). ||).y y Given the fully-qualified name of a class that is deployed inside and/or outside a JAR file.1-FLOOR.10TH MAIN. relational operators (limited to: <. Karnataka 560011 Phone: 22457577 Site Code: IIG95 16) IIHT-BANGALORE(FRANCHISE) IT HARBOUR SOLUTIN LTD # 101. <=. !. ^.

Karnataka 560010 Phone: 9845023146 y y y Section : 3-1.5: Given a scenario. Section : 7-1. y 560071 Phone: 41262390/41265144 Site Code: IIH7 18) NIIT LTD. Karnataka 560095 Phone: 080-41303291 Site Code: IIN40 20) SQL STAR INTERNATIONL LTDBANGALORE 40/4. FileReader. LAVELLE ROAD BANGALORE. NEAR ANAND SWEETS KORAMANGALA BANGALORE.1ST FLOOR.What is new in SCJP 1.0. writing to files. 986. develop the correct solution using the following classes (sometimes in combination).5: Given a code example. reading from files. Section : 6-1.6 ). 8TH E-MAIN. .0 exam except that few minor updates. BufferedWriter. 4THBLOCK JAYNAGAR BANGALORE.io: BufferedReader.JAYANAGARBANGALORE NIIT LTD 75. develop code that declares and/or invokes overridden or overloaded methods and code that declares and/or invokes superclass or overloaded constructors. determine what is and is not guaranteed by the garbage collection system. 60 FEET ROAD 5TH BLOCK. and recognize the behaviors of the Object. Objectives are very similar to SCJP 5. Write code that uses the NavigableSet ( mock exams ) and NavigableMap ( mock exams ) interfaces.41 ST CROSS3RD BLOCK RAJAJINAGAR Opp ESI Hospital BANGALORE. recognize the point at which an object becomes eligible for garbage collection. from java. Karnataka 560001 Phone: 2227781 Site Code: IIU2 21) CARTEL NETWORK SOLUTIONS (P) LTD. and Map interfaces and implementation classes.0.finalize() method. List. 3rd FLOOR. Recognize the behaviors of System. FileWriter. Karnataka 560011 Phone: 51211090 Site Code: IIN32 19) NIIT LTD KORAMANGALA NIIT LTD KORAMANGALA 143-B. and Console ( mock exams for console ). the Set. File. Section : 5-1.gc and finalization ( mock exams for garbage collection in scjp 1. In the following section bolded topics are updated in SCJP 6. Recognize the limitations of the non-generic Collections API and how to refactor code to use the generic versions. or interacting with the user. 1.6: Given a scenario involving navigating file systems. PrintWriter. recognize the point at which an object becomes eligible for garbage collection.6: Write code that uses the generic versions of the Collections API. in particular.6? There is few minor changes from the previous version 5. and determine what is and is not guaranteed by the garbage collection system.6: Given a code example.

In Collections Clearly understand how we can override hashCode and Equals methods. Kathy Sierra & Bert Bates is the best book for this exam. Storing and reading data to and from file. 4. Read the book 2 or 3 times & Clearly understand the topic and do all the questions given in this book at end of each chapter. 2. Familier the API for Array & Collections classes. Serialization follow the steps. For Generics & Collections. Locale. DateFormat. 3. Mocks exam question from java-beat. http://faq. Karnataka 560010 Phone: 23127771 Site Code: IIH37 23) NIIT LTD-VIJAYA NAGAR-BANGALORE 2934/E-II FLOOR MAGADI CHORD ROAD ABOVE FOOD WORLD VIJAYANAGAR II STAGE BANGALORE. Clearly Understand how the boxing & unboxing is working. 11. 7. 2011 By admin 44 Comments .Site Code: IIH23 1. 4.0 they covered vey well. Get familiar with the API for Date.6 ± Dump February 2. Karnataka 560001 Phone: 80-25585542 Site Code: IIO19 1. Make it clear in var args and Conversions (Wrapper to primitive & vice versa) 10. 5. They are very good. 9. http://www. If You want to pass. Like creation & working with directories. Clearly understand the rules for overloading and overriding. Threading. 6. 8. etc. Karnataka 560040 Phone: 41270768/41270769 Site Code: IIN34 24) APTECH COMPUTER EDUCATION 6TH FLOOR C WING MITTAL TOWERS MG ROAD BANGALORE. Calender.com/view?ScjpMockTests (You can get some question from that). For I/o. Familar the differences between all the Collection interfaces and Classes.net/ (for all old topics). 1.danchisholm. 3. Enums & Var-args I followed the mock questions from java-beat. Read 2 or 3 times and do all questions given. StringBUffer & StringBuilder.javaranch. Mocks exams done by me: y y y y 22) ROOMAN TECHNOLOGIES 130 1ST BLOCK RAJKUMAR ROAD RAJAJINAGAR BANGALORE. Write Simple programs to make it clear for Regular expressions & Static imports. Especillay for all new topics which are introduced for 5. that book is sufficient. String. good book is ks&B one only. Kathy Sierra & Bert Bates book questions + 2 mock exams (They are tough compared to real exam) 2.

} Options are A. 10. int) from the type A. int j){ return i+j.6)). 11. 6.println(add(s. 5.6 dumps please contact :admin@j2eereference. 8. 9. } public class B extends A{ public static void main(String argv[]){ short s = 9. 2. } } public class A { int add(int i. 3. The short s is autoboxed correctly. Compile fail due to error on line no 2 B. Compile fail due to error on line no 9 C. Cannot make a static reference to the non-static method add(int. 4. 15 Answer : B is the correct answer.out. 7.com Question ± 1 What is the output for the below code ? 1. System. Compile fail due to error on line no 8 D. but the add() method cannot be invoked from a static method because .For more SCJP 1.

printValue().0 0 0 . System. static int p.0 false 0 B.out. } } Options are A.out.print(istrue). Question ± 2 What is the output for the below code ? public class A { int k.print(p). boolean istrue.0 true 0 C.out.print(k).add() method is not static. public void printValue() { System. System. } } public class Test{ public static void main(String argv[]){ A a = new A(). a.

do=9.7 9 0 B.out. int $7. int do.println(test._$).out.out. System. System.$7). Default value of global and static int variable is zero. test. Question ± 3 What is the output for the below code ? public class Test{ int _$. Global and static variable need not be initialized before use.Compile error ± static variable must be initialized before use.7 0 0 . public static void main(String argv[]){ Test test = new Test(). Answer : A is the correct answer.println(test. } } Options are A.do).D.println(test. Remember local variable must be initialized before use. test.$7=7. System. Default value of boolean variable is false.

public class Cat extends Animal { public void printName(){ System.println(³Animal´). . import com. Question ± 4 What is the output for the below code ? package com. $7 is valid identifier. do is a Java keyword. } } package exam.out. D. Answer : D is the correct answer. class Animal { public void printName(){ System.Compile error ± do is not valid identifier.Animal. or underscore ( _ ).println(³Cat´). You can¶t use a Java keyword as an identifier.out. import com.Compile error ± $7 is not valid identifier. Identifiers cannot start with a number. Identifiers must start with a letter.Animal.C. } } package exam. a currency character ($).

printName(). a. Animal.public class Test { public static void main(String[] args){ Animal a = new Cat(). Question ± 5 What is the output for the below code ? public class A { int i = 10.println(³Value-A´).out. } } Options are A.Compile Error Answer : D is the correct answer.Animal B. has default access and is in a different package. public void printValue() { System. Cat class won¶t compile because its superclass.Cat C. } } .Animal Cat D. Only public superclass can be accessible for different package.

) then subclass method and super class variable will be executed.i). } } public class Test{ public static void main(String argv[]){ A a = new B().println(a. a. Question ± 6 .Value-B 11 B.Value-B 10 C.out.printValue().Value-A 11 Answer : B is the correct answer.out. public void printValue() { System. System.print(³Value-B´).Value-A 10 D. } } Options are A. If you create object of subclass with reference of super class like ( A a = new B().public class B extends A{ int i = 12.

} public int getMins() { return mm.getHour() +´:´+t. } public int getHour() { return hh. } public static void main(String args[]){ Test t = new BREAKFAST. } Question ± 7 What is the output for the below code ? .println(t. int mm) { assert (hh >= 0 && hh <= 23) : ³Illegal hour. private int mm.´. this. this.´. LUNCH(12.mm = mm.hh = hh. 45). Test(int hh. 15). System.out.getMins()). assert (mm >= 0 && mm <= 59) : ³Illegal mins.What is the output for the below code ? public enum Test { BREAKFAST(7. DINNER(19. 30). private int hh.

19:45 .} public A(){ System. } Options are A.println(³A´).A block static B.A Answer : B is the correct answer. } Options are A.12:30 D.out.7:30 B. First execute static block. } public static void main(String[] args){ A a = new A().out.Compile Error ± an enum cannot be instantiated using the new operator. then statement block then constructor.static A D.} { System.public class A { static{System. C.out.println(³static´).static block A C.println(³block´).

so its value is 8. 7. 6.out. int i = 010.out.8 7 B. Question ± 8 What is the output for the below code ? 1. System.Answer : B is the correct answer. public static void main(String[] args){ 3. } 8. } Options are A. 5.Compilation fails with an error at line 5 Answer : A is the correct answer. System. As an enum cannot be instantiated using the new operator. public class Test { 2.Compilation fails with an error at line 3 D. By placing a zero in front of the number is an integer in octal form. 4.10 7 C. 010 is in octal form . the constructors cannot be called explicitly. Question ± 9 . int j = 07. You have to do like Test t = BREAKFAST.println(j).println(i).

6. } 9.14 13 C. and /= will all put in an implicit cast.What is the output for the below code ? 1. System.out. So compiler complain about Type mismatch: cannot convert from int to byte for b = b+7. public class Test { 2. 7. -=.Compilation fails with an error at line 4 Answer : C is the correct answer.println(b). b += 7 is same as b = (byte)b+7 so compiler not complain. public static void main(String[] args){ 3. System.println(b). b+=8. int or smaller expressions always resulting in an int.Compilation fails with an error at line 6 D. *=. // No problem because +=. byte b = 6. b = b+7. 5.14 21 B. Question ± 10 What is the output for the below code ? . } Options are A. 4.out. But b += 7. 8.

changeValue(value). Java pass reference as value.Compilation fails D. } public static void changeValue(String a){ a = ³xyz´. passing the object reference.out. because the parameter is essentially a local variable. } } Options are A. Question ± 11 What is the output for the below code ? public class Test { .abc B.println(value).Compilation clean but no output Answer : A is the correct answer.xyz C. and not the actual object itself. System. Simply reassigning to the parameter used to pass the value into the method will do nothing.public class Test { public static void main(String[] args){ String value = ³abc´.

int C. But in this case compiler will prefer the older style before it chooses the newer style.println(³long´). printValue(b.b.println(³int´).out. var-args method is looser than widen. int k){ System.java inside src folder of javaproject . to keep existing code more robust. } public static void printValue(byte«b){ System.Compilation clean but throws RuntimeException Answer : B is the correct answer. (For Example if you pass short value to a method but method with short argument is not available then compiler choose method with int argument). } public static void main(String« args) { byte b = 9. Question ± 12 You have a java file name Test. Primitive widening uses the smallest method argument possible. int j. } } Options are A.long B.public static void printValue(int i.Compilation fails D.b).out.

javac src/Test.javac classes src/Test. You have also classes folder inside javaproject directory.out.java C.println(³Hello Test´).class inside javaproject directory.java source code is : public class Test{ public static void main (String[] args){ System. } } Test1.class file inside classes folder ? Options are A.java D. cd javaproject Which of the below command puts Test.class and Test1.directory.javac -d classes src/Test.class file it generates (d for destination) Question ± 13 You have two class files name Test.java B. The -d option lets you tell the compiler in which directory to put the .java Answer : A is the correct answer.javac Test.java source code is : public class Test1{ . Test. you have issued below command from command prompt.

You must specify exactly one class file to execute. cd javaproject java Test Test1 What is the output ? Options are A.java needs access to a class contained in app. Which of the follwing command set classpath to compile clean? Options are . If more than one then first one will be executed.public static void main (String[] args){ System.out.println(³Hello Test1 ).Run fails ± class not found Answer : A is the correct answer. Test.java .Hello Test Hello Test1 C. Question ± 14 You have a java file name Test.Hello Test B. } } you have issued below commands from command prompt.jar in ³exam´ directory.Hello Test1 D.

None of the above Answer : A is the correct answer. System.java C.jar in classpath.println(str + ´ ´ + signature).javac -classpath exam/app. Integer« data) { String signature = ³(String.A. Integer[])´.out. Question ± 15 What will be the result of compiling the following code: public class SuperClass { public int doIt(String str.jar Test.out.jar Test. System. } } public class SubClass extends SuperClass{ public int doIt(String str.jar Test.java B. return 1. Integer« data)throws Exception{ String signature = ³(String.javac -classpath app. Integer[])´. . javac -classpath exam/app.java D.println(³Overridden: ´ + str + ´ ´ + signature). return 0.javac -classpath exam Test.java is the correct command to set exam/app.

Select the one correct answer. Unhandled exception type Exception.None of the above Answer : C is the correct answer.} public static void main(String« args) { SuperClass sb = new SubClass(). for(int i = 2. } } Options are A. Options are . Integer[]) C. j < 4. i < 4. sb.doIt(³hello´. j++) if(i < j) assert i!=j : i.Overridden: hello (String.hello (String.Complilation fails D. Question ± 16 What happens when the following code is compiled and run. i++) for(int j = 2. 3). Integer[]) B.

j++) assert i!=j : i. B. Question ± 18 . When if condition returns true.compile error D. i++) for(int j = 2.The number 2 gets printed with AssertionError C.The number 3 gets printed with AssertionError Answer : B is the correct answer.A. but does not print anything. and AssertionError gets generated. B.The number 2 gets printed with AssertionError C. i < 4. for(int i = 2. . When i and j are both 2. but does not print anything.The class compiles and runs. Options are A.The class compiles and runs. Question ± 17 What happens when the following code is compiled and run. Hence AssertionError does not get generated. the assert statement also returns true.The number 3 gets printed with AssertionError Answer : A is the correct answer. Select the one correct answer. j < 4. assert condition is false.compile error D.

txt ? Options are A. Question ± 19 class A { A(String s) { } A() { } } 1.None Answer : C is the correct answer. }catch(Exception e){ }catch(IOException io){ } Is this code create new file name a.try{ File f = new File(³a. class B extends A { .True B.False C.Compilation Error D. IOException is unreachable to compiler because all exception is going to catch by Exception block.txt´).

void test() { 7. B(String s) { 4.2. B() { } 3.A a = new B(5). A a = new B().A a = new B(). // insert code here 8. C. B. } Which of the below code can be insert at line 7 to make clean compilation ? Options are A. } 9. D. is correct because anonymous inner classes are no different from any other class when it comes to polymorphism. } 6. 5. .All of the above Answer : A is the correct answer. Question ± 20 What is the output for the below code ? interface A { public void printValue(). super(s).A a = new A(String s).

null Answer : B is the correct answer. a1. A a1 = new A() { 4. } 7.printValue(). public static void main (String[] args){ 3. System.out.} 1. So no compilation error. The A a1 reference variable refers not to an instance of interface A. 8. public class Test{ 2. }. but to an instance of an anonymous (unnamed) class.A C. } Options are A.Compilation fails due to an error on line 8 D. 9. public void printValue(){ 5. } 10.Compilation fails due to an error on line 3 B. Question ± 21 class A { class A1 { . 6.println(³A´).

void printValue(){ System.out.println(³A.A1 ); } } } 1. public class Test{ 2. public static void main (String[] args){ 3. A a = new A(); 4. // INSERT CODE 5. a1.printValue(); 6. } 7. } Which of the below code inserted at line 4, compile and produce the output ³A.A1 ? Options are A.A.A1 a1 = new A.A1(); B.A.A1 a1 = a.new A1(); C.A a1 = new A.A1(); D.All of the above Answer : B is the correct answer. correct inner class instantiation syntax is A a = new A(); A.A1 a1 = a.new A1();

Question ± 22

What is the output for the below code ? public class A { public void printValue(){ System.out.println(³Value-A´); } } public class B extends A{ public void printNameB(){ System.out.println(³Name-B´); } } public class C extends A{ public void printNameC(){ System.out.println(³Name-C´); } } 1. public class Test{ 2. public static void main (String[] args) { 3. B b = new B(); 4. C c = new C(); 5. newPrint(b); 6. newPrint(c); 7. }

8. public static void newPrint(A a){ 9. a.printValue(); 10. } 11. } Options are A.Value-A Name-B B.Value-A Value-A C.Value-A Name-C D.Name-B Name-C Answer : B is the correct answer. Class B extended Class A therefore all methods of Class A will be available to class B except private methods. Class C extended Class A therefore all methods of Class A will be available to class C except private methods.

Question ± 23
What is the output for the below code ? public class A { public void printName(){ System.out.println(³Value-A´); } } public class B extends A{ public void printName(){ System.out.println(³Name-B´);

} } public class C extends A{ public void printName(){ System.out.println(³Name-C´); } } 1. public class Test{ 2. public static void main (String[] args) { 3. B b = new B(); 4. C c = new C(); 5. b = c; 6. newPrint(b); 7. } 8. public static void newPrint(A a){ 9. a.printName(); 10. } 11. } Options are A.Name-B B.Name-C C.Compilation fails due to an error on lines 5 D.Compilation fails due to an error on lines 9

return new C(). Question ± 24 What is the output for the below code ? public class C { } public class D extends C{ } public class A { public C getOBJ(){ System. Reference variable can refer to any object of the same type as the declared reference OR can refer to any subtype of the declared type. } } public class B extends A{ public D getOBJ(){ System. } } public class Test { .out. return new D().out.println(³class A ± return C´). Reference variable ³b´ is type of class B and reference variable ³c´ is a type of class C.Answer : C is the correct answer.println(³class B ± return D´). So Compilation fails.

} } Options are A.class B ± return D C.class A ± return C B.Compilation succeed but no output Answer : B is the correct answer.Compilation fails D.getOBJ().0 onwards.println(³Value-A´).public static void main(String« args) { A a = new B().out. Question ± 25 What is the output for the below code ? public class A { private void printName(){ System. From J2SE 5. } } public class B extends A{ public void printName(){ . return type in the overriding method can be same or subtype of the declared return type of the overridden (superclass) method. a.

System.println(³Name-B´). b. private method is not availabe in subclass .Name-B C. So you can call printName() method of class B. printName() method of class B different method. } } public class Test{ public static void main (String[] args) { B b = new B().Value-A B.FileNotFoundException. In this case printName() method a class A is not overriding by printName() method of class B. Question ± 26 What is the output for the below code ? import java. } } Options are A.io.printName(). You can not override private method .Value-A Name-B D.Compilation fails ± private methods can¶t be override Answer : B is the correct answer.out. public class A { .

println(³Name-B´).Compilation fails-Exception NullPointerException is not compatible with throws clause in A. } } Options are A. } } public class Test{ public static void main (String[] args) throws Exception{ A a = new B().public void printName() throws FileNotFoundException { System. a.printName().out. . } } public class B extends A{ public void printName() throws NullPointerException{ System.Value-A B.printName() C.Name-B D.Compilation succeed but no output Answer : C is the correct answer.println(³Value-A´).out.

regardless of exception thrown by overridden method. } } public class B extends A{ public B (){ System.println(³B´).out. System.out.println(³A´). Question ± 27 What is the output for the below code ? public class A { public A(){ System.out.println(i+3). } } public class Test{ .The overriding method can throw any unchecked (runtime) exception.println(i). NullPointerException is RuntimeException so compiler not complain. } public B (int i){ this(). System. } public A(int i){ this().out.

Then come to constructor of class B (public B (int i)). Question ± 28 What is the output for the below code ? 1.public static void main (String[] args){ new B(5). which execute first.A B 8 B. } public class Test implements InfA{ public String getName(){ return ³test-name´. protected String getName(). public interface InfA { 2.A B 5 D. and that constructors can be overloaded. 3.B 8 A 5 Answer : A is the correct answer. } public static void main (String[] args){ . } } Options are A.A 5 B 8 C. Constructor of class B call their superclass constructor of class A (public A()) .

only public and abstract are Permitted Question ± 29 What is the output for the below code ? public class D { int i. this. System. .getName().Compilation fails due to an error on lines 1 D. } } Options are A. Illegal modifier for the interface method InfA.out.int j){ this.out.i=i.test-name B.j=j.println(t. } public void printName() { System.Compilation fails due to an error on lines 2 C.Compilation succeed but Runtime Exception Answer : B is the correct answer. int j.getName()). public D(int i.Test t = new Test().println(³Name-D´).

d. public class Test{ 2. 6.Compilation succeed but no output Answer : B is the correct answer. Question ± 30 public class A { public void test1(){ .printName(). D d = new D(). public static void main (String[] args){ 3. a default constructor will be automatically generated by the compiler.Compilation fails due to an error on lines 3 C.Name-D B.} } 1. the compiler won¶t supply a default constructor. If you want a no-argument constructor to overload the with arguments version you already have. Since there is already a constructor in this class (public D(int i. you have to define it by yourself. } 7. 4.int j)).Compilation fails due to an error on lines 4 D. } Options are A. If no constructor into your class . 5. If you define explicit constructor then default constructor will not be available. You have to define explicitly like public D(){ } then the above code will work. The constructor D() is undefined in class D.

test2(). . B b1 = new B(). 4. // insert code here 7. D.out. inserted at line 6. } 8. 5.out.(B)b.System. A a = new A(). } } public class B extends A{ public void test2(){ System.println(³test2 ).test2(). public class Test{ 2. B. 6. } Which of the following .println(³test1 ).test2(). A b = new B(). will compile and print test2? Options are A.((B)b). public static void main (String[] args){ 3.b. C.a.test2(). } } 1.

Question ± 31 What is the output for the below code ? 1.10 D.out.println(x). 4. (B)b.test2(). public class Test { 2. System. ((B)b). x *= 3 + 7. x *= 3 + 7.22 B. 6. int x =5. test2() method is in class B so need to cast b then only test2() is accessible.Compilation fails with an error at line 4 Answer : B is the correct answer. is proper cast. 5. is same as x = x * (3 +7) = 5 * (10) = 50 because expression on the right is always placed inside parentheses.50 C.the compiler thinks it is an incomplete statement. is not proper cast without the second set of parentheses. } 7. Question ± 32 . public static void main(String« args) { 3.Answer : A is the correct answer.test2(). } Options are A.

MAR }. enum Month { JAN. 9. } 12.true true false false C.out.out.equals(m2) returns true because enum constant value is same (JAN and JAN).true true true false B.println(m1. 8. FEB. 10. } Options are A.equals(m2)). public static void main(String« args) { 4. public class Test { 2.FEB. Month m2 = Month.equals(m3)). 5.false false true true D. m1 and m2 refer to the same enum constant So m1 == m2 returns true BUT m1 and m3 refer to different enum constant So m1 == m3 returns false.println(m1 == m2). System.out. m1. 6.out. Month m3 = Month.equals(m3) return false because enum constants values are different (JAN and FEB). 11.JAN.What is the output for the below code ? 1. 3.println(m1. System.Compilation fails with an error at line 10 Answer : B is the correct answer. System.println(m1 == m3). Month m1 = Month. System. 7. m1. .JAN.

System.false C.println(index instanceof Object). b=6.Compilation fails with an error at line 4 Answer : A is the correct answer.out.println(a + b +c). } Options are A. 4. System.out. public static void main(String« args) { 3. An array is always an instance of Object Question ± 34 What is the output for the below code ? public class Test { public static void main(String« args) { int a =5 . public class Test { 2. int [] index = new int[5].out. } 6.println(³Value is ³+ b +c). System. .true B.Compilation fails with an error at line 3 D.Question ± 33 What is the output for the below code ? 1. c =7. 5.

If the left hand operand is not a String then + operator treat as plus BUT if left hand operand is a String then + perform String concatenation.Compilation fails Answer : A is the correct answer.Value is 67 18 String 13 B.out.println(³B´). } .Value is 13 18 String 13 C.out. } } Options are A. Question ± 35 What is the output for the below code? public class A { public A() { System.Value is 13 18 String D.out.println(³A´).println(³String ³+(b+c)).System. } } public class B extends A implements Serializable { public B() { System.

} public class Test { public static void main(String« args) throws Exception { B b = new B(). save.B Answer : A is the correct answer. So constructor of class B does not called.A B A B C. Question ± 36 .B B D. A is not Serializable object so constructor is called. B z = (B) restore.flush().A B A B. } } Options are A. the Serializable object not create new object. save. On the time of deserialization . ObjectOutputStream save = new ObjectOutputStream(new FileOutputStream(³datafile´)).writeObject(b). ObjectInputStream restore = new ObjectInputStream(new FileInputStream(³datafile´)).readObject().

readObject().println(³A´).A A B.flush(). } } public class Test { public static void main(String« args) throws Exception { A a = new A(). } } Options are A.What is the output for the below code? public class A { public A() { System. A z = (A) restore.NotSerializableException D. ObjectOutputStream save = new ObjectOutputStream(new FileOutputStream(³datafile´)). save.out.java.A C.None of the above . save.writeObject(a). ObjectInputStream restore = new ObjectInputStream(new FileInputStream(³datafile´)).io.

Answer : C is the correct answer.out.Compile error D.None of the above Answer : . int l = 34. Question ± 37 What will be the result of compiling and run the following code: public class Test { public static void main(String« args) throws Exception { Integer i = 34.out. } } } Options are A. }else{ System.equals(l)){ System. if(i.false C.println(false).println(true). So throws NotSerializableException on trying to Serialize a non Serializable object.true B. Class A does not implements Serializable interface.

So file.A is the correct answer. Question ± 39 .false true C. you¶re not yet making an actual file. file.exists() return false.true true B.exists()). creating a new instance of the class File.exists() return true.exists()).println(file.so file.false true D. equals() method for the integer wrappers will only return true if the two primitive types and the two values are equal.createNewFile(). Question ± 38 What will be the result of compiling and run the following code: public class Test { public static void main(String« args) throws Exception { File file = new File(³test. createNewFile() method created an actual file.out. System. System.println(file.out.None of the above Answer : B is the correct answer.txt´). } } Options are A. you¶re just creating a filename.

os.Compilation Fail B.ser´). } } } Options are A.None of the above . try{ FileOutputStream fs = new FileOutputStream(³b. }catch(Exception e){ e. public static void main(String« args){ B b = new B(). os.close().java.No Exception at Runtime D.What is the output for the below code ? public class A {} public class B implements Serializable { private static A a = new A().writeObject(b).printStackTrace().NotSerializableException: Because class A is not Serializable.io. C. ObjectOutputStream os = new ObjectOutputStream(fs).

run-test run-test B. public class Test extends Thread{ 2.io. No java. Test t = new Test().Compilation fails due to an error on line 4 D.run-test C. t.Answer : C is the correct answer. 4.NotSerializableException.println(³run-test´).run(). Because class A variable is static. System. public static void main(String argv[]){ 3. public void run(){ 8.out.Compilation fails due to an error on line 7 Answer : .start(). 6. } 10. t. static variables are not Serializable. } 7. 5. } Options are A. 9. Question ± 40 What will happen when you attempt to compile and run the following code ? 1.

6.start(). t.out. 4. } 8.run-a run-a C.Compilation succeed but Runtime Exception .run() Legal. t.A is the correct answer. } Options are A.println(³run-a´). public class Test { 2.start().start() create a thread and call run() method.Compilation fails with an error at line 6 D. it is like a method call of class Test BUT t. 7. t. Thread t = new Thread(a). 5. public static void main(String« args) { 3.run-a B. } } 1. but does not start a new thread . Question ± 41 What is the output for the below code ? class A implements Runnable{ public void run(){ System. A a = new A().

Thread t1 = new Thread(a.´A´). t. .lang.start() throws java.i++){ Thread.i<4.sleep(100). Once a thread has been started.Answer : D is the correct answer.´B´).getName()). } }catch(InterruptedException e){ } } } public class Test { public static void main(String argv[]) throws Exception{ A a = new A().out. 2nd time t. Question ± 42 What is the output for the below code ? class A implements Runnable{ public void run(){ try{ for(int i=0. System.println(Thread.start().IllegalThreadStateException. it can never be started again. Thread t = new Thread(a.currentThread().

start(). }catch(InterruptedException e){ } } public synchronized void printValue(){ . } } Options are A. means Threat t must finish before Thread t1 start.out.join().A B A B A B A B C.Compilation succeed but Runtime Exception Answer : A is the correct answer.t. Question ± 43 What is the output for the below code ? public class B { public synchronized void printName(){ try{ System.Output order is not guaranteed D.sleep(5*1000). t. t1.println(³printName´).A A A A B B B B B. Thread.join().

public static void main(String argv[]) throws Exception{ Test t = new Test(). } } public class Test extends Thread{ B b = new B(). } } } Options are A.start().print : printName then print : printValue . t1. Thread t1 = new Thread(t.equals(³t1 )){ b.start().println(³printValue´). }else{ b.getName(). Thread t2 = new Thread(t.out.printValue().currentThread().´t2 ). } public void run(){ if(Thread.System. then wait for 5 seconds then print : printValue B. t2.print : printName .´t1 ).printName().

no other thread can pick up the lock until the first thread releases the lock.sleep(5*1000).Compilation succeed but Runtime Exception Answer : A is the correct answer. So other threads can not access the object.println(³printValue´). If one synchronized method of an instance is executing then other synchronized method of the same instance should wait. if one thread has picked up the lock. }catch(InterruptedException e){ } } public synchronized void printValue(){ System. Thread.out. .C.print : printName then wait for 5 minutes then print : printValue D.out. Question ± 44 What is the output for the below code ? public class B { public static synchronized void printName(){ try{ System. } } public class Test extends Thread{ B b = new B().println(³printName´). printName() method acquire the lock for 5 seconds. There is only one lock per object.

´t1 ).print : printName then print : printValue C.start(). Thread t1 = new Thread(t. t1.printName().print : printName then wait for 5 minutes then print : printValue D.printValue(). no other thread can pick up the lock until the first thread releases the lock.equals(³t1 )){ b. } } } Options are A.start(). There is only one lock per object.public static void main(String argv[]) throws Exception{ Test t = new Test(). }else{ b. In this case printName() is static .print : printName .currentThread(). Thread t2 = new Thread(t. if one thread has picked up the lock.Compilation succeed but Runtime Exception Answer : B is the correct answer.´t2 ).getName(). So lock is in . then wait for 5 seconds then print : printValue B. t2. } public void run(){ if(Thread.

a. A static synchronized method and a non static synchronized method will not block each other.println(³waiting´). i++){ count = count + i.out.println(³run´). i < 50 . synchronized (this) { for(int i =0. try{ . } } } public class Test{ public static void main(String argv[]) { A a = new A(). public void run(){ System.class B not instance b. } notify(). synchronized (a) { System. Question ± 45 What is the output for the below code ? class A extends Thread{ int count = 0.start(). both method (one static and other no-static) can run simultaneously.out.

out.wait().waiting run 0 C.waiting run and count can be anything D. put thread on wait until not get notifed. i++){ System. .count).println(a.a.Compilation fails Answer : A is the correct answer. } } } Options are A. A thread to call wait() or notify(). i < 2. the thread has to be the owner of the lock for that object. }catch(InterruptedException e){ } System. It doesn¶t execute any further instructions until the notify() method of the target object is called.out. a.wait(). Question ± 46 Which of the following statements about this code are true? class A extends Thread{ public void run(){ for(int i =0. A thread gets on this waiting list by executing the wait() method of the target object.waiting run 1225 B.println(i).

class A extends Thread means the anonymous instance that is passed to check() method has a start method which then calls the run method.start().check(new A(){}). class A has no start method C. Question ± 47 HashMap can be synchronized by _______ ? .Compilation error. } } Options are A.Compilation succeed but runtime exception Answer : C is the correct answer. } public void check(A a){ a. t.0 1 D.} } } public class Test{ public static void main(String argv[]){ Test t = new Test().0 0 B.

} public static void show(Queue q) { q.Map m = hashMap.add(³newyork´).LinkedList.add(new Integer(11)). show(q). HashMap can be synchronized by Map m = Collections.Options are A.synchronizeMap(hashMap).Map m = Collection. B.synchronizeMap(hashMap). Question ± 48 What is the output for the below code? import java.synchronizeMap(). C.Map m = Collections.synchronizeMap(hashMap). D.None of the above Answer : A is the correct answer.util.isEmpty ( ) ) .add(³texas´). q.Queue. q.add(³ca´). import java.util. while (!q. public class Test { public static void main(String« args) { Queue q = new LinkedList(). q.

s. import java. If the show method signature is public static void show(Queue<String> q) than you can¶t add Integer.System.util. or returns null if this queue is empty. But in show() method it is passed as an untyped Queue. s.Iterator. ´ q was originally declared as Queue<String>.util.util. nothing in the compiler or JVM prevents us from adding an Integer after that.poll() + ´ ³). public class Test { public static void main(String« args) { Set s = new TreeSet(). import java.add(³7 ). Only String allowed.Y poll() Retrieves and removes the head of this queue. } } Options are A.newyork ca texas D. Question ± 49 What is the output for the bellow code? import java.None of the above Answer : B is the correct answer. .print(q.newyork ca texas 11 C.Compile error : Integer can¶t add B. But public static void show(Queue q) is untyped Queue so you can add Integer.out.Set.TreeSet.add(9).

iterator().String cannot be cast to java.Compile error B.Integer.Iterator itr = s.Runtime Exception C. import java. Question ± 50 What is the output for the below code? import java.out. } } Options are A. public class Test { public static void main(String« args) { TreeSet s1 = new TreeSet(). the compiler does not know what type is appropriate for this TreeSet. .lang.7 9 D.hasNext()) System. so it allows everything to compile.lang.Iterator. But at runtime he TreeSet will try to sort the elements as they are added. while (itr.util. | Without generics. and when it tries to compare an Integer with a String it will throw a ClassCastException.next() + ´ ³).util.lang.ClassCastException: java.TreeSet.None of the above Answer : B is the correct answer.print(itr. ? Exception in thread ³main´ java.

s1. Iterator it = s1. s1. Question ± 51 If we do ArrayList lst = new ArrayList(). for Strings means alphabetical.add(³three´).one two three Answer : A is the correct answer.it will return elements in natural order.one three two B.add(³two´). } } } Options are A. while (it. s1. which. h TreeSet assures no duplicate entries.add(³one´).iterator().one three two one D.hasNext() ) { System. What is the initial capacity of the ArrayList lst ? .s1.out.add(³one´).Runtime Exception C.next() + ´ ´ ).print( it.

public class Abc { public static int index_val = 10.12 Answer : A is the correct answer.out.Options are A. import static bean.15 D. public class Test1 { public static void main(String« args) { System.Abc. } Question ± 52 What is the output for the below code ? package bean. /** * Constructs an empty list with an initial capacity of ten. } } Options are .println(index_val).10 B. */ public ArrayList() { this(10). } package com.8 C.index_val.

index_val. The static import construct allows unqualified access to static members without inheriting from the type containing the static members. C.class inside javaproject directory.util. D. Question ± 54 You have a class file name Test. B.10 B.Abc. Question ± 53 Which of the following statement is true about jar command? Options are A.Abc.A.The jar command creates the MANIFEST. All statements are true.0 onwards it allows static import like import static bean.Compile error at import static bean. and can be use directly System.Properties.index_val.java source code is : import java.None of the above Answer : A is the correct answer. D.The jar command would not place any of your files in META-INF directory. J2SE 5.The jar command creates the META-INF directory implicitly.MF file implicitly. Test.out.println(index_val). index_val not defined C.All of the above are true Answer : A is the correct answer. .compile error.

NoClassDefFoundError: key1=value1.println(p.getProperty(³key1 )). no spaces allowed.Run fails ± java. In this case there is space between -D and key1=value1 So java.null C.lang. } } you have issued below commands from command prompt.getProperties(). Question ± 55 What is the output for the below code ? public class A { . -D option .out.NoClassDefFoundError: key1=value1 Answer : D is the correct answer.class Test { public static void main (String[] args){ Properties p = System.Run successfully but no output D. System.value1 B. pair must follow immediately.lang. cd javaproject java -D key1=value1 Test What is the output ? Options are A.

} } 1. 9.out.A B. 4. public static void main(String« args) { 3. public class Test { 2.println(³B´). A b = new B(). } 11.printValue(). public static void newValue(A a){ 7. ((B)a). } 6. } 10. } Options are A. 5.out. if(a instanceof B){ 8.println(³A´). newValue(b).public void printValue(){ System. } } public class B extends A { public void printValue(){ System.B .

Compilation fails with an error at line 4 D.out.5 6 7 16 B. b is instance of B So works properly.out.C.println(i).\ Question ± 56 What is the output for the below code ? 1.6 6 7 16 D. instanceof operator is used for object reference variables to check whether an object is of a particular type. static int i =5. 7.println(i++). System. } 10. public static void main(String« args) { 4.out. 5. 9.Compilation fails with an error at line 8 Answer : B is the correct answer. System. 8.println(++i).println(++i+i++). 6.out.6 6 6 16 C.5 6 6 16 . 3. In newValue(b). System. public class Test { 2. } Options are A. System.

6. public static void main(String« args) { 3.println(str). } Options are A. 4.out. .Answer : A is the correct answer.feb B.jan C. i++ : print value then increment (postfix ± increment happens after the value of the variable is used) ++i : increment the print (prefix ± increment happens before the value of the variable is used) Question ± 57 What is the output for the below code ? 1. (i<21) is false goto (i<56).Compilation fails with an error at line 4 Answer : A is the correct answer. Integer i = 34. (i<56) is true so result is ³feb´. System.march D. This is nested conditional with unbox. String str = (i<21)?´jan´:(i<56)?´feb´:´march´. 5. } 7. public class Test { 2.

zero or more times X+ X.matches(). } } Options are A.matcher(³ab´).true B.Compile error D. X? X.None of the above Answer : A is the correct answer. one or more times Question ± 59 What is the output for the below code ? 1.Question ± 58 What is the output ? public class Test { public static void main(String« args) { Pattern p = Pattern. System.false C. Matcher m = p.println(b). public static void main(String[] args){ 3. .out. once or not at all X* X. public class Test { 2. boolean b = m. byte i = 128.compile(³a+b?c*´).

} . 3. public static void main(String[] args){ 5. add().4.Compilation fails with an error at line 4 Answer : C is the correct answer. } 6. } Options are A. public static void add(){ 8. public class Test { 2. 9. } 7. int i=8. 10.Compilation fails with an error at line 3 D. System.println(i). byte can only hold up to 127.out. 5. int k = i+j.0 C. int j=9.128 B.println(k). 6. Question ± 60 What is the output for the below code ? 1.out. System. 4. So compiler complain about possible loss of precision.

11.util.util.util.java.List C.java. but methods are not synchronized? Options are A. Question ± 62 What is the output of bellow code ? .0 C.Compilation fails with an error at line 5 D. } Options are A.Compilation fails with an error at line 8 Answer : D is the correct answer. So Compilation fails .util.Vector Answer : A is the correct answer. i and j are instance variable and attempting to access an instance variable from a static method.java. Question ± 61 Which collection class grows or shrinks its size and provides indexed access to its elements.ArrayList B. | ArrayList provides an index to its elements and methods are not synchronized.HashSet D.java.17 B.

} return ((Bean) o).util.HashSet. Bean(String str ){ this.public class Bean{ private String str. } } import java. public class Test { . } public String getStr() { return str. } public boolean equals(Object o){ if (!(o instanceof Bean)) { return false.equals(str).getStr(). } public String toString() { return str.str = str. } public int hashCode() { return 12345.

add(s3). myMap.println(myMap). } } Options are A.add(s4). System.das Answer : A is the correct answer. Question ± 63 What will happen when you attempt to compile and run the following code . Bean s3 = new Bean(³abcdef´).add(s1). myMap. Bean s4 = new Bean(³abcdef´).add(s2).das abcdef B.out.das abcdef das abcdef C. myMap. String s1 = new String(³das´). myMap. String s2 = new String(³das´).public static void main(String « sss) { HashSet myMap = new HashSet().das das abcdef abcdef D. implemented µequals¶ and µhashCode¶ methods to get unique result in Set.

out.isAlive()). 4.start(). System. A a = new A(). 8.println(t. the thread is considered to be alive.true run-A true D.isAlive()). } 9.println(t. t.out.? class A implements Runnable{ public void run(){ System. Once the start() method is called. } Options are A.println(³run-A´).Compilation fails due to an error on line 7 Answer : A is the correct answer. 7. System. . public static void main(String argv[]){ 3.out. 5. 6. } } 1.false run-A true B. Thread t = new Thread(a).false run-A false C. public class Test { 2.

run-test run-test B. public static void main(String argv[]){ 3. it is like a method call of class Test BUT t. public class Test extends Thread{ 2.run() Legal.start(). } Options are A. System. 6. 4.Compilation fails due to an error on line 4 D.run(). but does not start a new thread .println(³run-test´). 5. 9.out.start() create a thread and call run() method.run-test C.Question ± 64 What will happen when you attempt to compile and run the following code ? 1. } 7.Compilation fails due to an error on line 7 Answer : A is the correct answer. public void run(){ 8. t. } 10. t. Question ± 65 . t. Test t = new Test().

Check out the Java2 Docs for an explanation Question ± 66 What notifyAll() method do? Options are A.Wakes up all threads that are not waiting on this object¶s monitor D.Which of the following are methods of the Thread class? 1) yield() 2) sleep(long msec) 3) go() 4) stop() Options are A.1 .1 and 3 C. 2 and 4 B.None of the above Answer : A is the correct answer. notifyAll() : Wakes up all threads that are waiting on this object¶s monitor.Wakes up all threads that are waiting on this object¶s monitor B.Wakes up one threads that are waiting on this object¶s monitor C.A thread waits .None of the above Answer : A is the correct answer.3 only D.

size()). navMap.out.println(navMap. ³January´).put(3. } } Options are A. ³June´). ³April´). navMap. ³March´). navMap. navMap.ConcurrentSkipListMap.on an object¶s monitor by calling one of the wait methods.pollLastEntry().put(2.Compile error : No method name like pollFirstEntry() or pollLastEntry() .put(4. Question ± 67 What is the output for the below code? import java.NavigableMap.pollFirstEntry().util. public class Test { public static void main(String« args) { NavigableMap navMap = new ConcurrentSkipListMap().util.put(1.put(5. navMap. ³May´).pollFirstEntry(). ³February´). navMap. import java. navMap. navMap. System.concurrent. navMap.put(6.

3 C.B. Y pollLastEntry() Removes and returns a key-value mapping associated with the greatest key in this map. Question ± 68 What is the output for the bellow code? import java. or null if the map is empty.console(). if (con != null) { int count = 0.Console.None of the above Answer : B is the correct answer. char[] pwd = con. boolean auth = false.6 D.io. do { String uname = con. or null if the map is empty. public class Test { public static void main(String« args) { Console con = System.readLine(null). Y pollFirstEntry() Removes and returns a key-value mapping associated with the least key in this map.readPassword(³Enter %s¶s .

Iterator.util. Question ± 69 What is the output for the below code? import java. import java.ArrayList.util. import java. $ passing a null argument to any method in Console class will cause a NullPointerException to be thrown.util.write(³\n\n´).util. } while (!auth && ++count < 3).NullPointerException B.password: ³.It works properly C. con.TreeSet.None of the above Answer : A is the correct answer. public class Test { . uname).List.Compile Error : No readPassword() method in Console class.NavigableSet. import java.writer(). D. import java.util. } } } Options are A.

} } Options are A. lst.add(6).true)). 7. q headSet(10.2.println(nvset. System.Compile error : No method name like headSet() B.add(7). 8.headSet(10.true) Returns the elements elements are strictly less than or equal to 10.out. 8 D. lst.headSet(10. NavigableSet nvset = new TreeSet(lst). À headSet(10) Returns the elements elements are strictly less than 10.2.add(2). 6.add(8).None of the above Answer : B is the correct answer.add(10). lst.add(34). . 6.public static void main(String« args) { List lst = new ArrayList (). lst. 7.false) Returns the elements elements are strictly less than 10. Question ± 70 . 10 C. lst. lst.

lst.What is the output? import java.ArrayList.add(8).util.println(nvset.TreeSet. lst.util.out. lst. System.add(10). } } Options are A. import java. public class Test { public static void main(String« args) { List lst = new ArrayList(). NavigableSet nvset = new TreeSet(lst).1 2 7 10 34 null B. lst.util. import java.add(7).lower(2)). lst.List.higher(6)+ ³ ³+ nvset. import java.add(6).NavigableSet.add(34).2 7 null C.add(2).lower(6)+´ ³+nvset.util. lst.2 7 34 .

û lower() Returns the greatest element in this set strictly less than the given element.D.1 2 7 10 34 Answer : B is the correct answer. or null if there is no such element. or null if there is no such element. . ¿ higher() Returns the least element in this set strictly greater than the given element.

Sign up to vote on this title
UsefulNot useful