Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Learn Java Programming - Java Practice Tests

Practice with 600 Java Programs and 1750 MCQs. These practice tests helps in reinforcing your learning. They can keep you busy for months together.

  • Be the first to comment

  • Be the first to like this

Learn Java Programming - Java Practice Tests

  1. 1. Ifyou are the first person to give the Correct Answerand Explanation, then you are eligible for a mobile recharge. The amounts are Rs.40 for First Comment, Rs.30 for Daily Dose Second Comment and Rs.20 othen/ vise. O 4 1 More Details at http: //java. meritcampusxom/ dailydose Request: Please reviewthe previous comments before postingyouranswer. Post 23-Jan-2013 m 9 only if you think none ofthe previous comments are correct. Note: The processingofthe recharge can take up to 7 days. fpublic class Increment 5 l i ' public static void main(String[] args) < E A a : new A(5); a. increment () ; I a. operate() ; : a = new A(a. i); a. operate() ; a. increment (J ; System. out. print1n("i = ‘ + a. i); E l E I } I class A E l E int i : 0; A(int i) E l E this. i = i + 4: E i E void increment() : l : i = this. i + 1; E l E void operate() E i E : 1 '- 3. : E l E E l E I = 1 lEl i = 103 if i = 55 W Compilation Error
  2. 2. Ifyou are the first person to give the Correct Answerand Explanation, then you are . eligible fora mobile recharge. The amounts are Rs.4o for First Comment, R530 for Daflv Dose Secondcommentand Rs. N otherwise. More Details at http: //iava. meritcampuscom/ dailydose Request: Please reviewthe previous comments before postingyouranswer. Post only if you think none ofthe previous comments are correct. 24']an'2o13 Note: The processing of the recharge can take upto 7 days. What will be the output of the following program? class Operations I int v; public static void main(String[] args) ( new Operations () . add(5) . print() . sub(7) . print() . mu1tiply(3) . add(3) . print() . sub(4) . print(); l Operations add(int i) ( v+¢i, ' return this; ] Operations sub(int i) ( v-—i; return this; } Operations m'u1tip1y(int j) ( V'= j; return this; ) Operations print() ( SysteIn. out. println("v = " + V); return this; } Compilation Error
  3. 3. If you are the first person to give the Correct Answerand Explanation, then you are eligible fora mobile recharge. The amounts are Rs.40 for First Comment, Rs.30 for Second Commentand Rs.20 othenrvise. More Details at http: //J'ava. meritcampus. com/ dailydose Request: Please reviewthe previous comments before posting youranswer. Post onlyif you think none ofthe previous comments are correct. 25'Jan'2o]-3 Note: The processing of the recharge can take upto 7 days. Daily Dose class Roonmndfan I l V public static void mainlstrinqll args) l Room r = new Roomll ' . name : "Hall": . f1ooring = larble": width = r. height = 127 . fan. speed = 1500,- . fan. color = "Bro‘vm“. ' . fa. n.number0fHings = 3,‘ System. out. println(r. name + r. flooring + (r. vridth + r. height) + r. fan. speed + r. fa. n.color + r. fa. n.numberOfWings) 7 public static void a(Room r) l r. f1ooring = "Italian “ + r. f1ooring: r. height = (r. width + 12 + 1), - r. fan. number0fHings = 4: lclass Room ( String name; String flooring; int width, height; Fan fan; ) class Fan ( double s ed' Strin co1or' int numberoflrlin s: } Ha| |Marb| e241S00.0Brown3 Hallltalian Marb| e371500.0Brown4 C Ha| |Marb| e12121500.0Elrown3 D Compilation Error E Runtime Error
  4. 4. Ifyou are the first person to give the Correct Answerand Explanation, then you are eligible for a mobile recharge. The amounts are Rs.40 for First Comment, Rs.30 for Second Comment and Rs.20 otherwise. More Details at http: //java. meritcampus. com/ dailydose Request: Please reviewthe previous comments before postingyouranswer. Post only if you think none ofthe previous comments are correct. Note: The processing of the recharge can take up to 7 days. merit What will be the output of the following program? class I-lobile Daily Dose O44 26-Jan-2013 I ( E String model, maker; E int numberofsims: , double memory; I-{obile(String model, String maker, int numberofsims, double memory) ( I this. model = model; I ; this. maker : maker; ; E t: his. numberOfSi_ms : numberofsims; I this. memory : memory; E l E public static void main(String[] args) I i I Mobile m : new l-{obile("Samsumg", "Wave 525", 1, 2048.0) ; Mobile 11 : new l-iobile("Nokia" , "Lumia", 2, 25000.0) ; I imprint (m) ; n. print(n) ; I Mobile 1: = n; I I n = m: I m = t; m. print(n) ; n. print(n) ; E i E E public void print (Mobile in) E ( E System. out. println(model + " " + maker + “ “ + numberofsims + " " + memory); E l E : ) ' Samsumg Wave 525 1 2048.0 ‘A‘ Nokia Lumia 2 25000.0 — Samsumg wave 525 1 2048.0 Samsumg Wave 525 1 2048.0 Samsumg wave 525 1 2048.0 E‘ Nokia Lumia 2 25000.0 — Nokia Lumia 2 25000.0 Nokia Lumia 2 25000.0 Samsumg Wave 525 1 2048.0 Nokia Lumia 2 25000.0 —— Nokia Lumia 2 25000.0 Samsumg Wave 525 1 2048.0 Compilation Error EB Runtime Error
  5. 5. Ifyou are the first person to give the Correct Answerand ExpIanation, thenyou are eligible fora mobile recharge. The amounts are Rs.40 for First Comment, Rs.30 for Daily Dose Second Commentand Rs.20 otherwise. More Details at http: //java. meritcampus. com/ dailydose Request: Please reviewthe previous comments before postingycuranswer. Post 27-Jan-2013 only if you think none ofthe previous comments are correct. Note: The processing of the recharge can take upto 7 days. How many objects of O are created? " Epublic class 0 O o : new O(); public static void main(String[] args) ( O o = new O(); o. creat: e(); l public void creat: e() o = new O(); l 4 l Compilation Error l Runtime Error
  6. 6. If you are the first person to give the Correct Answerand Explanation, then you are eligiblefora mobile recharge. The amountsare Rs.4o for First Comment, R530 for Dan)’ Dose Second Comment and Rs.20 otherwise. 0 4 6 More Details at http: //java. me ritcampus. com/ dailydose Request: Please review the previous comments before posting your answer. Post onlyif you think none ofthe previous comments are correct. 28'Jan'2o13 Note: The prooessingof the recharge can take upto 7 days. What will be the output of the following program? static int c = 0; public static void main(Stringl] args) l W 171 c(); H w2 c(w1); W w3 c(w2), ' W w4 c(w3); l private lrl ( ) I System. out. pri. nt1.n("c = " + c); l static H c() i return CH <= 0 ? new 910 : null; l static W c(W w) i return w. c-H- = 1 ? new W() Compilation Error
  7. 7. If you are the first person to give the Correct Answerand Explanation, then you are eligible fora mobile recharge. The amounts are Rs.40 for First Comment, Rs.30 for Second Commentand Rs.20 othenivise. More Details at http: //java. meritcampus. com/ daiIydose _ Request: Please reviewthe previous comments before postingyouranswer. Post ment onlyifyouthink none ofthe previous comments are correct. 29']an'2o13 Note: The processing ofthe recharge can take up to 7 days. Daily Dose At what line will the run—time exception occur? " -1 class I-{Test I i E public static void main(String[] args) I | : new M(); = new N(); : LINE A = new O(); o; // LINE B 2 : (o) m: // LINE c = (N) m; // LINE 1: 205052: E’Ol| Ol| §5 5 E l Eclass M l } Eclass N extends I-l { } Eclass 0 extends M ( ) All LINE A El LINE B 0} LINE c l 1} LINE D El Compilation Error
  8. 8. If you are the first person to give the Correct Answerand Explanation, then you are eligible fora mobile recharge. The amounts are Rs.40 for First Comment, Rs.30 for Second Commentand Rs.20 otherwise. More Details at http: //lava. nieritcanipusxoni/ daiIydose Re uest: Please review the revious comments before ostin ouranswer. Post onllyifycuthink none ofthegrevicuscomments are correct. gy 30-Jan'2o13 Note: The processing ofthe recharge can take up to 7 days. Daily Dose What will be the output of the following program? " class A'l‘est E i public static Void main(String[] args) I a : new A(), ' . print(): b : new Bl): .print()7 t : b: .print(), ' l = b; .printl); (B) t; .print(), ' (B) a; .print()r U"O"U‘U‘niWrV. ’flU‘ulW. ’P' l Eclass A ( void print(l l System. out. print("A")7 ) i Eclass B extends A ( void print() ( System-out-pr'1nt("B"); i I l A ABABBB lb; ABBABB l c ABBBBB lD Compilation Error l E Runtime Error - C| assCastException
  9. 9. Ifyou are the first person to give the Correct Answerand Explanation, then you are eligible for a mobile recharge. The amounts are Rs.40 for First Comment, Rs.30 for Second Comment and Rs.20 othenn/ ise. More Details at http: //java. meritcampus. com/ dailydose Request: Please reviewthe previous comments before postingyouranswer. Post only if you think none ofthe previous comments are correct. Note: The processingofthe recharge can take up to 7 days. Daily Dose O49 31-Jan-2013 Eclass ConstructorsTest public static void main(String[] args) : l l U U V V T T i ll Eclass U ( ' Vv = U() l _ U(int El lclass V{ V() { , V(int El u = new U(); ul : new U(1); v : new V(); v1 = new V(1); t = new T0; t1 = new ’l'(1); new V(); System . out . print ( "U" ) ; ) 11) System. out . print ( "V" ) : ) i) lclass T extends V { gm { System. out. print("T"); ) { System. out. print("u") ll { System. out. print; ("v"); ) E'I'(int i) { System. out. print("t"); ) : l UuVvVTvt VUVuVvVTvt VUVuVvVTVt Compilation Err Runtime Error — OI’ goes into infinte loop
  10. 10. merit Ifyou are the first person to give the Correct Answerand Explanation, then you are eligible fora mobile recharge. The amounts are Rs.40 for First Comment, Rs.30 for Second Comment and Rs.20 otherwise. More Details at http: //java. meritcampus. com/ dailydose Request: Please reviewthe previous comments before postingyouranswer. Post only if you think none ofthe previous comments are correct. Note: The processingofthe recharge can take up to 7 days. Daily Dose 050 01-Feb-2013 What will be the output of the following program? Epublic class DailyDoseAmount E l public static void main(String[] args) ( printAmount(40, 0); printAmount (350 , 28) ; printAmount (528 , 72) ; printAmount (713 , 129) ; print'. Amount(687 , 634) : print. Amount(812, 389) , - l public static void print; Amount(int numberOfPriends, int number0fFollowers) l amount amount amount , System. out. println(”For ” Efollowers, the int amount : "2 10; : l-{ath. max(40, = I-lath. min(100, amount) 7 amount) : + numberOfl: "riends + " an‘-. oLmt is " + amount); (numbel-: OfFriends + numberOfFollowers) / 100: Friends and " + numberOfl: "ollowers + " l )> E l For 40 Friends and 0 Followers, the amount is 0 For 350 Friends and 28 Followers, the amount is 30 For 528 Friends and 72 Followers, the amount is 40 For 713 Friends and 129 Followers, the amount is 40 For 687 Friends and 634 Followers, the amount is 40 For 812 Friends and 389 Followers, the amount is 40 For 40 Friends and 0 Followers, the amount is 40 For 350 Friends and 28 Followers, the amount is 40 For 528 Friends and 72 Followers, the amount is 60 For 713 Friends and 129 Followers, the amount is 80 For 687 Friends and 634 Followers, the amount is 100 For 812 Friends and 389 Followers, the amount is 100 For 40 Friends and 0 Followers, the amount is 100 For 350 Friends and 28 Followers, the amount is 100 For 528 Friends and 72 Followers, the amount is 100 For 713 Friends and 129 Followers, the amount is 100 For 687 Friends and 634 Followers, the amount is 130 For 812 Friends and 389 Followers, the amount is 120 Compilation Error
  11. 11. Ifyou are the first person to give the Correct Answerand Explanation, then you are eligible for a mobile recharge. The amounts are Rs.40 for First Comment, Rs.30 for Daily Dose Second Commentand Rs.20 otherwise. 0 5 1 More Details at http: //lava. meritcampusrom/ dailydose Request: Please reviewthe previous comments before posting youranswer. Post 02-Feb-2013 onlyif you think none ofthe previous comments are correct. Note: The processing of the recharge can take up to 7 days. Eabstract class I E ( : abstract void i1(); 3 ) Eabstract class J extends I ii 2 void i1() () E) Eabstract class K extends J : i ' abstract void i2(); A i I, J, K El J, K El K All of them compile l i
  12. 12. Ifyou are the first person to give the Correct Answerand Explanation, then you are eligible for a mobile recharge. The amounts are Rs.40 for First Comment, Rs.30 for Dally Dose Second Comment and Rs.20 othen/ vise. 0 5 2 More Details at http: //java. meritcampus. com/ dailydose _ Request: Please reviewthe previous comments before postingyouranswer. Post onlyifyou think none ofthe previouscomments are correct. Note: The processingofthe recharge can take up to 7 days. What will be the output of the following program? ' . class Total ( 1 int a. b, total; ; static int c; 1 Total(int a, int b, int c, int total) ( I this. a = a; this. b : b; this. c = c; this. total = total; I I ) I ‘ Total(int a, int 13, int c) ( 3 this(a, b, c, a+b+c); i l 'I‘otal(int a, int b) ( ; this(a, b, c, a+b+c), ' ) public void print() { System. out. print1n("c = " + c + " total = “ + total); I c = total; I 1 i 3 1 public static void main(String[] args) ( i 1 Total t1 = new '['otal(4, 7, 2, 4 + '7 + 2); 1 Total t2 = new Total(tl. a, tl. b, tl. c); t1.pr)'. nt() , ' 1 Total t3 : new 'I‘otal(t1.c, t2.c); t2.print() : t3.print() 7 t1.print() ; l 1 l ‘ : i . c = 2 total = 13 c = 13 total = 13 — c = 13 total = 6 c = 6 total = 13 c = 2 total = 13 ‘ B" c = 13 total = 13 c = 13 total = 39 c = 39 total = 13 c = 2 total = 13 ? c = 2 total = 13 — c = 0 total = 26 c = 13 total = 13 E Compilation Error 1? Run- time Error
  13. 13. Ifyou are the first person to give the Correct Answerand Explanation, then you are eligible for a mobile recharge. The amounts are Rs.40 for First Comment, Rs.30 for Second Comment and Rs.20 othen/ vise. 0 5 3 More Details at http: //java. meritcampus. com/ dailydose Request: Please reviewthe previous comments before postingyouranswer. Post 04-Feb-2013 m e only if you think none ofthe previous comments are correct. Note: The processingofthe recharge can take up to 7 days. Daily Dose What will be the output of the following program? ‘ iclass Product ( public static void main(String[] args) { new M(). product(3); new N(). product(3); new O(). product(3); Eclass M { ' int product(int i) ( int result = i ' i: System. out. print("( ” + i + ” ” + result + ” } "J; return result; It Eclass N extends M ( ' int product(int i) ( int result : super. product(i) ‘ super. product(i): System. out. print("[ " + i + " “ + result + " ] "); return result; iclass 0 extends M ( int product(int i) ( int result = super. product(i) ‘ i; System. out. print("( " + i + “ = “ + result + " ) "); return result: ) iij {3=9}{3=9}{3=9}j3=81]{3= }(3=27‘i iii {3=9}{3=9}{3=9}j3=s1‘{3=9}{3=9}j3=a1;(3=243) lg {3=9}{3=9}(3=27){3=9}{3=9}i3=a1] Compilation Error i E Run-time Error
  14. 14. If you are the first person to give the Correct Answerand Explanation, then you are . elgible fora mobile recharge. The amounts are Rs.40 for First Comment, Rs.30 for Dady Dose Second Commentand Rs.20 otherwise. More Details at http: //lava. meritcampusrom/ dailydose Request: Please reviewthe previous comments before postingyouranswer. Post only if you think none ofthe previous comments are correct. Note: The prooessingofthe recharge can take upto 7 days. What will be the output of the following program? Epublic class Smiley‘l‘est { ' public static void Iiain(Strinq[] args) ( Smile a - new Sni1e(); ta]. k(a) ; a. frown() ; l public static void talk(ISni1e inl) ( System. out. print(" : —0 "); ia1.snile () . ' ' l -interface Ifiiile ( ' void sIni1e(); 5 l lclass Smile implements Ismile ( void s| ni1e() ( Systun. out. print(" : -) "); i void frown() ( Isnile a1 - new S! nile(); al. i1e() ; Systan. out. pri. nt(" : —[ "); Compilation Error [E] I
  15. 15. If you are the first person to give the Correct Answerand Explanation, then you are eligible for a mobile recharge. The amounts are Rs.40 for First Comment, R530 for Daily Dose Second Commentand Rs.20 othen/ vise. 0 5 5 More Details at http: //Java. meritcampusrom/ dailydose Request: Please review the previous comments before posting youranswer. Post 06-Feb-2013 onlyif you think none ofthe previous comments are correct. Note: The processing ofthe recharge can take upto 7 days. Which of the following classes fail to compile. " linterface I1 ( void m1() ; ) iinterface I2 extends I1 { void m2() , ' ) labstract class A implements I1 { ‘ public void m1() ii ‘ public void In2() () 3 i labstract class B implements I2 () fclass C extends A implements 11, I2 H iclass D extends A () l_/3, A, B, c, D lE B, c, D ii B, c ll C l E All of them compile
  16. 16. If you are the first person to give the correct Answerand Exp| anation, then you are eligible fora mobile recharge. The amounts are R5110 for First Comment, Rs.30 for second Comment and Rs. m otherwise. More Details at http: //lava. meritcampusrom/ dailydose Request: Please reviewthe previous comments before postingyouranswer. Post only if you think none of the previous comments are correct. Note: The prooesslngofthe recharge can take upto 7 days. What will be the output of the following program? Epublic class final ( int lanif - 37; int nafi - 21; public static void i| ai. n(Stri. ng[] args) ( final Final f - new Pinal(). ' f. process2() i Final f2 - modify(f) ; f2.process2()i l public static final final nodify(final final f) ( f. process () ; linal f2 = new ! inal(); f2.proceas(), - return f2; l final void process () ( lanif - nafi + nafi; SysteIn. out. pri. nt(lanif + " " + nafi + " "); l void process2() l nafi - lanif / 2; SysteIn. out. pri. nt(nafi + " " + lanif + " "li Daily Dose 056 07-Feb-2013 18 37 36 ll! 18 37 36 18 Compilation Error
  17. 17. Ifyou are the first person to give the Correct Answerand Explanation, then you are eligible for a mobile recharge. The amounts are Rs.40 for First Comment, Rs.30 for Second Comment and Rs.20 otherwise. 0 5 7 More Details at http: //lava. meritcampus. com/ dailydose Request: Please reviewthe previous comments before postingyouranswer. Post 08-Feb-2013 m e only if you think none ofthe previous comments are correct. Note: The processing of the recharge can take up to 7 days. Daily Dose public class Rust ( public static void main(String[] args) ( 1 new R() . m2() 7 new U() . m1(), ' 1 new S(). m1(); 1 new T(). m1(); 1 l 3 iclass R ( 1 private void m1() { 7 1 System. out. print("R") ; 1 I l I public void m2 () ( 11110 7 3 l 3 E l 3 Eclass U ( protected void ml () ( System. out. print(”U”) 7 3 l 3 public void m2() ( 1 ml () ; I 1 new R0 . m2 () 7 1 1 i 3 3 l 3 lclass S ( 1 public void mli) ( 1 System. out. print("S”) 7 I new U(). ml()7 3 > 3 E i 3 lclass T ( 1 void ml () ( 1 System. out. print("'I‘”) 7 3. > 3 E l 3 A RUSUT E1 RSUTU RUST El Compilation error in the method m2 of class R E Compilation error for some other reason
  18. 18. Ifyou are the first person to give the Correct Answerand Explanation, then you are . eligible fora mobile recharge. The amount of recharge is linked to the number of Dally Dose friends and followers we have. It can varyfrom Rs.40 to Rs. 100. O 5 8 More Details at http: //java. meritcampus. com/ dailydose . ‘ Request: Please reviewthe previous comments before postingyouranswer. Post m e| "|'| _' only if you think none ofthe previous comments are correct. Note: The processingofthe recharge can take up to 7 days. 09-Feb-2013 What will be the output of the following program? ‘ Eclass Recursivefor 3 E i E public static void main(String[] args) 1 i 1 int out = 157 : for (int i : 4; i < 6; i++) E i E for (int j : 7; j >= 5; j--) } i if (i = = j) continue; 1 if (i > j) : i 3 out += main(i, j); E > 5 else 5 l I out += mainij, i); : ) : } 1 l E System. out. println(”out : ” + out); 5 l 1 private static int main(int a, int b) : l if (a — b = 0) E i 5 return 27 E l 1 return a + main(a - 1, b): E l E i . 12 out = 78 1E1 out = 71 1? out = 80 El Compilation Error Goes into infinite loop
  19. 19. if you are the first person to give the Correct Answer and Explanation, then you are . eligible fora mobile recharge. The amount of recharge is linked to the numberof Dafly Dose friendsand followers we have. It can varyfrom Rs.40 to Rs.100. 9 More Details at http: //java. merit(ampus. com/ dailydose _ Request: Please reviewthe previous comments before postingyouranswer. Post onlyif you think none ofthe previouscomments are correct. Note: The processing ofthe recharge can take upto 7 days. 10-Feb-2013 What lines of the following program gets executed, given that the exceptions are thrown at LINE B, at LINE D and at ihfiirllg LINE F. ‘ 3 “Y : i 3 / / LINE A try ( / / LINE B » I catch (Exception ex) ( / / LINE C : l/ LINE D t): atch(Exception e) ( LINE E / / LINE E‘ 33/. ..': I.*. '3*. .(: .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... . . . A A, B,C, D,E, F,G jg A, B, E, F, G C A, B, C, D, E, F
  20. 20. Ifyou are the first person to give the Correct Answerand Explanation, then you are D . | D eligible fora mobile recharge. The amount of recharge is linked to the number of 3' Y 059 friends and followers we have. It can varyfrom Rs.40 to Rs. 100. O More Details at http: //lava. meritcampus. com/ dailydose Request: Please reviewthe previous comments before postingyouranswer. Post m only if you think none ofthe previous comments are correct. Note: The processing of the recharge can take up to 7 days. 11-Feb-2013 What will be the output of the following program? ' 1class I-{arkerInterfaces l public static void main(String[] args) { E System. out. println(”G = “ + G. PI)7 I System. out. println("H 2 ” + H. PI); 5 CG cg : new CG(); 5 System. out. println("cg = “ + cg. PI); cg. PI "= 2; I System. out. println("cg = “ + cg. PI); E System. out. println(”G = ” + G. PI); E l 'interface G ( double PI = 3.14; 3} Einterface H extends G ( double PI = 3.145,- 3l 3 lclass CG implements G ( double PI : 3.1451; c = 3.14 i H = 3.14 lAl cg = 3.14 cg =3.14 <; = 3.14 <3 = 3.14 i H = 3.14 131 cg = 3.1451 cg =6.2902 <; = 3.14 <3 = 3.14 i H = 3.145 lcl cg = 3.1451 cg =6.2902 <; = 3.14 <3 = 3.14 i H = 3.145 [31 cg = 3.1451 cg =6.2902 <3 =6.2902 Compilation Error

    Be the first to comment

    Login to see the comments

Practice with 600 Java Programs and 1750 MCQs. These practice tests helps in reinforcing your learning. They can keep you busy for months together.

Views

Total views

454

On Slideshare

0

From embeds

0

Number of embeds

3

Actions

Downloads

16

Shares

0

Comments

0

Likes

0

×