0% found this document useful (0 votes)
8 views

WrittenTest On CoreJava

written test on Core Java for Testing coding skills

Uploaded by

Pavan Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
8 views

WrittenTest On CoreJava

written test on Core Java for Testing coding skills

Uploaded by

Pavan Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
Clinical Software Pvt. Lid _Java Trainee Written Test Instructions: 4. Total duration 4 ¥% hr 2. Question1 to 19 has single answer. 3. Question 20 to 30 has multiple answers. 4. Don't write anything on question paper. 1) What is the output of the following? StringBuffer sb1 = new StringBuffer(‘Amit") StringBuffer sb2 = new StringBuffer("Amit’), String ssi = "Amit"; System.out printin(sb1==sb2); ‘System.out.printin(sb1 .equals(sb2)); ‘System.out.printin(sb1 .equals(sst)); ‘System.out printin("Poddar".substring(3)); 2) What is the output of the following? String s1 = new String("amit") String 82 = s1.replace( 'm, ''), s1.concat("Poddar"}; System.out.printin(s1); ‘System.out.printin((s1+82).charAt(5)); famitPoddar 0 a) | ce famit | 3) Whats the result of attempting to compile the following code? 4. class OutThing ( 2. class Aninner { 3. public inti 44 5, public static void main(String (] args) { 6. Antnner aninn = new Antnner() 7 aninn.i= 15; 8.) 9} © |the code complies without error [p)[© [ompiter error at tine 3 | © |Compiier error at ine 6 © [Compl error at line 7 | sthod? © Boolean | co ‘bona 5) What will be the output of the following? double dt = -0.5d; ‘System. out printin("Gel for d1” +Math.ceil(d1)): System.out printin(*Floor for di” +Math floor(at)) \eeifordt0 OCS a ») co allfor dt 0 | Floor for dt 4 LPS [Foor for at -1.0 (Ceil for d1 0.0 PG (Cell for d je [Floor for dt -1.0; a Je Floor for d1 1.0; 6) What will be the output of the following Boolean b1 = new Boolean("TRUE"); Boolean b2 = new Boolean("truo"): Boolean 53 = new Boolean("JUNK"), ‘System.out printin(’™+ bt + b2 +53); [ar] ero oor fale |rwetuetase Run time error iiruetruetrue 7). Inthe previous question if line 4 is changed to System,out.printin(bt *b2#b3); The output is [a [© [Compite tie error | fe ]© hruetuetaise 8) Look at the following code import java.awt. public class visual extends java applet.Applet { static Button b = new Button("TEST"), public void init() add(b); public static void main(String args{)) { Frame f = new Frame("Visual"); f-setSize(300,300); fadd(oy, fsetVisible(true); } } ‘What will happen if the above code is run as a standalone application? [ a) le [pispiays an empty frame | b) ~ [Displays a frame with a button large “_enough to accomodate its label. plays a frame with a button covering the | lentire frame | 9) What is the value of the following expression? Math.round(Math.random()+2.50001); fae e) | [tis impossible to say. 40) If a java program imports a large number of classes, what is the runtime impact? [ale fale _ here is moderate impact atruntime, | d) | © [There is significant impact at runtime, ‘ner is no impact at runtime [by [© [There is sight impact at rntie, 41) What will be the result of attempting to compile and run the following code? abstract class MineBase { abstract void amethod();, static int j public class Mine extends MineBase public static void main(string argv) { int{] ar=new intfS]; for(i=0; i < ar.length;i++) System out printin(arfl) } fale [ole [asequence of os will be printed [Error Mine must be declared abstract by | Enron: aris used before its initialized @) [© |jdexoutorBoundes Error 42) For a class defined inside a method, what rule governs access to the variables of the enclosing method? ied class can access any variable al (= [The cass can only access transient variables [6 [© Ime class can only access static variables ‘ale The class can only access final variables 13) Which of the following lines will compile without waming or error? 114) What is the result of the following operation? ‘system outprintin(4/3); [ule ichar ale lo ale fr 15) What will happen if you attempt to compile an Integer ten=new Integer(10); Long nine=new Long(9), System.outprintin(tensnine); inti=t; System.out printin(i+ten); run the following code? ja [e |19 folowed by 20 (>) | {19 followed by 11 ————— — fe [© ror Cannot convert java lang integer | d) | [10 folowed by 4 16) How many objects are created by the code listed below? String s1 = "abo"; 17) What happened when you try to compile the following code and execute the Dolphin application? class Animal (} . class Mammal extends Animal class Cat extends Mammalt) . class Dolphin extends Mammal { public static void main(string args() ( Mammal m = new Catt); Animal a =m; . Dolphin ¢ = (Dolphin)a; } line 6. ‘The code compiles without error 's an exception at line 8. t 18) You need to create a class that will store uniqué ‘The code compiles with no error | a) © fandruns without throwing any |b) | Compiler error at line 6. lexceptons, \ — [Compiler error at ine 7. [a |~ [Compiter error attine 8. ~The code compiles without error | nc code compiles without error and throws an lexception at line 7. fe object elements. You do not need to sort these elements but they must be unique. What interface might be most suitable to meet this need? | | J 19) Which of the following will successfully create an instance of the vector class and add an element? a) | new Vector’), ey vaddElement(99); °) le \Vector venew Vector \vaddElement(’99") 20) Which one does not extend java.tang. Number? {integer ‘Boolean ] ie 21) Consider the following ciass definition public class Test extends Base public Testint j) { ) public Test(intj int k) ( supers} } ‘What of the following forms of constructor must exist explicilly in the definition of the Base class? [oF benno” © [a) | feasetit) int nt 0 import java. awi.*; lpackage Mypackage; class Myciass (} pis is a comment * ipackage MyPackage; | | import java.awt.*, class MyClass) 23) What can cause a thread to stop executing? a) Ir [he program exits via a call to exi(0; ‘The priority of another thread is inereased | = [Acallto the stop method of the Thread Jeall to the halt method of the Thread oir air class lass: = — 24) Which of the following lines of code will compile without error? | boolean b=true; ] I boolean b2=true; air by i(o==b2) { | | [Sostem out printin'So tne”, | | | | | ei! ja) ir i |System.out printin("OK"); 25) Which of the following methods would be allowed in a subclass of parent? (Choose all permitted methods) Note: EOFException is a subclass of IOException, class Parent { void abede(int i) throws IOException if (10) throw new IOException(); fa |r poi abode(byte 7 \void abede(byte 1 throws Et [ey [Float aedettye tows EOFExcepton a) | [eee jo Fh ptatio vol abee( int) throws IOException | 26) Which of the following methods would be allowed in a subclass of parent? (Choose all permitted methods) Note: EOFException is a subclass of IOException, class Parent void abede(int i) throws IOException { if (10) throw new IOException(); d [a1 [F foisabededint) ~[b) ; ‘oid abedetint) tows Exception °) ri abede(int) throws IOException [a oa abede{int) throws EOFException ey |r Noid abede(int) throws IOException, ) | |Eorexception 7 27) When you run class C as an application, which of the following lines execute? 1 interface inter) 2. class Al} 3. class Brextends A implements Inter(} 4, class C extends B { 5. public static void main(string ] args) { 6.Aa=new A); 7. B b=new Bi); 8. C cenew Cl); 9. fa instanceof B) 40. System.out.printin("Hello"); 11. if(b instanceof A) 42. System.out printin(’Hello”); 43. if(¢ instanceof C) 14, System.out.printin("Hello”); 15. I{(C instanceof Inter) 16, System.out printin("Hello”);, 17.) 18) 2 \r «tne 10 [a Ir ‘line 12 [ar Fee 16 28) Which of the following code fragments generate compiler error? [a [F pootean too [oy [F[breb=6;charc=b; [phar ot ="a'y shor ser; er [F Jong ton = 1; float jo Ir lat 1 = 2L; tong font a) Ir lan inner class may be declared private. [oir [An inner class defined in a method should ° An inner class defined in a method cai ‘always be anonymous laccess all the method local variables ‘Construction of an inner class may require | ian instance of the outer class. 30) Which variable may be correctly referenced at jine 8” 1. public class Outer { 2, public int a 5. private int 4. public void method final int c) { 5. intd = 6 7. class inner { private void iMethod(int e) { 9.) 10.) wir

You might also like